Skip to content

Commit

Permalink
Fixes to parser and WASM library stuff (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave authored Nov 20, 2023
1 parent c10b772 commit 0ece1ad
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 185 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/lines-of-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ jobs:
- name: Run update script
run: |
cargo metadata --offline --format-version 1 --no-deps | jq -r ".workspace_members[]" | while read -r name version pathInfo ; do
linesOfRustCode=$(scc -c --no-cocomo -f json -i rs ${pathInfo:13:-1} | jq '.[] | .Code');
path=${pathInfo:13:-1}
if [[ -d "$path/src" ]] ; then
linesOfRustCode=$(scc -c --no-cocomo -f json -i rs "$path/src" | jq '.[] | .Code');
else
linesOfRustCode=$(scc -c --no-cocomo -f json -i rs $path | jq '.[] | .Code');
fi
curl \
--header "Content-Type: application/json" \
--header "X-POST-ACCESS-KEY: ${{ secrets.PROJECTS_POST_ACCESS_KEY }}" \
--data "{\"project\":\"$name\",\"language\":\"rust\",\"loc\":$linesOfRustCode}" \
-w "\nUpdated-project: \n" \
https://projects.kaleidawave.workers.dev/update-project;
echo "\`$name\` has $linesOfRustCode lines of code" >> $GITHUB_STEP_SUMMARY;
echo "\`$name\` has $linesOfRustCode lines of code"Y;
done
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ package = "ezno-checker"

[dependencies.parser]
path = "./parser"
version = "0.0.8"
version = "0.1.0"
features = ["extras"]
package = "ezno-parser"

Expand Down
3 changes: 1 addition & 2 deletions checker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ categories = ["compilers"]

[features]
default = []
# declaration-synthesis = []
ezno-parser = ["parser"]

[dependencies]
Expand Down Expand Up @@ -45,6 +44,6 @@ erased-serde = "0.3"
[dependencies.parser]
path = "../parser"
optional = true
version = "0.0.8"
version = "0.1.0"
features = ["extras"]
package = "ezno-parser"
31 changes: 9 additions & 22 deletions checker/src/synthesis/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,11 @@ pub(super) fn synthesise_class_declaration<

// TODO abstract
let (getter_setter, is_async, is_generator) = match &method.header {
Some(MethodHeader::Get(_)) => (GetterSetter::Getter, false, false),
Some(MethodHeader::Set(_)) => (GetterSetter::Setter, false, false),
None => (GetterSetter::None, false, false),
Some(
MethodHeader::Generator(is_async, _)
| MethodHeader::GeneratorStar(is_async, _),
) => (GetterSetter::None, is_async.is_some(), true),
Some(MethodHeader::Async(_)) => (GetterSetter::None, true, false),
MethodHeader::Get(_) => (GetterSetter::Getter, false, false),
MethodHeader::Set(_) => (GetterSetter::Setter, false, false),
MethodHeader::Regular { r#async, generator } => {
(GetterSetter::None, r#async.is_some(), generator.is_some())
}
};

let method_ty = environment.new_function(
Expand Down Expand Up @@ -187,27 +184,17 @@ pub(super) fn synthesise_class_declaration<
ParserPropertyKey::Ident(_, _, true) => Publicity::Private,
_ => Publicity::Public,
};
let (is_async, is_generator) = match &method.header {
None | Some(MethodHeader::Set(_)) | Some(MethodHeader::Get(_)) => {
(false, false)
}
Some(
MethodHeader::Generator(is_async, _)
| MethodHeader::GeneratorStar(is_async, _),
) => (is_async.is_some(), true),
Some(MethodHeader::Async(_)) => (true, false),
};
let behavior = FunctionRegisterBehavior::ClassMethod {
is_async,
is_generator,
is_async: method.header.is_async(),
is_generator: method.header.is_generator(),
// TODO
super_type: None,
};
let function = environment.new_function(checking_data, method, behavior);

let value = match method.header {
Some(MethodHeader::Get(_)) => PropertyValue::Getter(Box::new(function)),
Some(MethodHeader::Set(_)) => PropertyValue::Setter(Box::new(function)),
MethodHeader::Get(_) => PropertyValue::Getter(Box::new(function)),
MethodHeader::Set(_) => PropertyValue::Setter(Box::new(function)),
_ => PropertyValue::Value(checking_data.types.new_function_type(function)),
};

Expand Down
14 changes: 5 additions & 9 deletions checker/src/synthesis/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ pub(super) fn synthesise_object_literal<T: crate::ReadFromFS>(
for member in members.iter() {
let member_position = member.get_position().clone().with_source(environment.get_source());
match member {
ObjectLiteralMember::SpreadExpression(spread, pos) => {
ObjectLiteralMember::Spread(spread, pos) => {
checking_data.raise_unimplemented_error(
"spread in object literal",
pos.clone().with_source(environment.get_source()),
Expand Down Expand Up @@ -992,19 +992,15 @@ pub(super) fn synthesise_object_literal<T: crate::ReadFromFS>(
);

let behavior = crate::behavior::functions::FunctionRegisterBehavior::ObjectMethod {
is_async: method.header.as_ref().map(|h| h.is_async()).unwrap_or_default(),
is_generator: method
.header
.as_ref()
.map(|h| h.is_generator())
.unwrap_or_default(),
is_async: method.header.is_async(),
is_generator: method.header.is_generator(),
};

let function = environment.new_function(checking_data, method, behavior);

let property = match &method.header {
Some(MethodHeader::Get(_)) => crate::PropertyValue::Getter(Box::new(function)),
Some(MethodHeader::Set(_)) => crate::PropertyValue::Setter(Box::new(function)),
MethodHeader::Get(_) => crate::PropertyValue::Getter(Box::new(function)),
MethodHeader::Set(_) => crate::PropertyValue::Setter(Box::new(function)),
_ => {
crate::PropertyValue::Value(checking_data.types.new_function_type(function))
}
Expand Down
15 changes: 7 additions & 8 deletions checker/src/synthesis/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub(super) fn synthesise_signatures<T: crate::ReadFromFS, B: SynthesiseInterface
for member in members {
match &member.on {
InterfaceMember::Method {
kind,
header,
name,
type_parameters,
parameters,
Expand All @@ -143,18 +143,16 @@ pub(super) fn synthesise_signatures<T: crate::ReadFromFS, B: SynthesiseInterface
position,
} => {
let behavior = functions::FunctionBehavior::Method {
is_async: kind.as_ref().map_or(false, |header| header.is_async()),
is_generator: kind.as_ref().map_or(false, |header| header.is_generator()),
is_async: header.is_async(),
is_generator: header.is_generator(),
// TODO ...
free_this_id: TypeId::ERROR_TYPE,
};
let getter = kind.as_ref().map_or(GetterSetter::None, |header| match header {
let getter = match header {
parser::MethodHeader::Get(_) => GetterSetter::Getter,
parser::MethodHeader::Set(_) => GetterSetter::Setter,
parser::MethodHeader::GeneratorStar(_, _)
| parser::MethodHeader::Generator(_, _)
| parser::MethodHeader::Async(_) => GetterSetter::None,
});
_ => GetterSetter::None,
};
let function = synthesise_function_annotation(
type_parameters,
parameters,
Expand Down Expand Up @@ -212,6 +210,7 @@ pub(super) fn synthesise_signatures<T: crate::ReadFromFS, B: SynthesiseInterface
return_type,
is_readonly,
position,
performs,
} => checking_data.raise_unimplemented_error(
"interface constructor",
position.clone().with_source(environment.get_source()),
Expand Down
2 changes: 1 addition & 1 deletion parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ezno-parser"
description = "Parser and AST definitions for Ezno"
authors = ["Ben <[email protected]>"]
version = "0.0.8"
version = "0.1.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/kaleidawave/ezno"
Expand Down
2 changes: 1 addition & 1 deletion parser/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc-macro = true
quote = "1.0"
proc-macro2 = "1.0"
self-rust-tokenize = "0.3.3"
ezno-parser = { path = "..", version = "0.0.8", features = [
ezno-parser = { path = "..", version = "0.1.0", features = [
"self-rust-tokenize",
] }

Expand Down
14 changes: 6 additions & 8 deletions parser/src/declarations/classes/class_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl ASTNode for ClassMember {
.conditional_next(|tok| *tok == TSXToken::Keyword(TSXKeyword::Readonly))
.map(|token| Keyword::new(token.get_span()));

let header = MethodHeader::optional_from_reader(reader);
let header = MethodHeader::from_reader(reader);
let key = WithComment::<PropertyKey<_>>::from_reader(reader, state, options)?;

match reader.peek() {
Expand Down Expand Up @@ -181,7 +181,7 @@ impl ClassFunction {
reader: &mut impl TokenReader<TSXToken, crate::TokenStart>,
state: &mut crate::ParsingState,
options: &ParseOptions,
get_set_generator: Option<MethodHeader>,
get_set_generator: MethodHeader,
key: WithComment<PropertyKey<PublicOrPrivate>>,
) -> ParseResult<Self> {
FunctionBase::from_reader_with_header_and_name(
Expand All @@ -196,15 +196,15 @@ impl ClassFunction {

impl FunctionBased for ClassFunctionBase {
type Body = Block;
type Header = Option<MethodHeader>;
type Header = MethodHeader;
type Name = WithComment<PropertyKey<PublicOrPrivate>>;

fn header_and_name_from_reader(
reader: &mut impl TokenReader<TSXToken, crate::TokenStart>,
state: &mut crate::ParsingState,
options: &ParseOptions,
) -> ParseResult<(Self::Header, Self::Name)> {
let header = MethodHeader::optional_from_reader(reader);
let header = MethodHeader::from_reader(reader);
let name = WithComment::<PropertyKey<_>>::from_reader(reader, state, options)?;
Ok((header, name))
}
Expand All @@ -216,14 +216,12 @@ impl FunctionBased for ClassFunctionBase {
options: &crate::ToStringOptions,
depth: u8,
) {
if let Some(header) = header {
header.to_string_from_buffer(buf);
}
header.to_string_from_buffer(buf);
name.to_string_from_buffer(buf, options, depth);
}

fn header_left(header: &Self::Header) -> Option<source_map::Start> {
header.as_ref().map(|header| header.get_start())
header.get_start()
}
}

Expand Down
48 changes: 24 additions & 24 deletions parser/src/expressions/object_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct ObjectLiteral {
#[cfg_attr(feature = "self-rust-tokenize", derive(self_rust_tokenize::SelfRustTokenize))]
#[cfg_attr(feature = "serde-serialize", derive(serde::Serialize))]
pub enum ObjectLiteralMember {
SpreadExpression(Expression, Span),
Spread(Expression, Span),
Shorthand(String, Span),
Property(WithComment<PropertyKey<AlwaysPublic>>, Expression, Span),
Method(ObjectLiteralMethod),
Expand All @@ -39,7 +39,7 @@ impl crate::Visitable for ObjectLiteralMember {
chain: &mut temporary_annex::Annex<crate::Chain>,
) {
match self {
ObjectLiteralMember::SpreadExpression(_, _) => {}
ObjectLiteralMember::Spread(_, _) => {}
ObjectLiteralMember::Shorthand(_, _) => {}
ObjectLiteralMember::Property(_, _, _) => {}
ObjectLiteralMember::Method(method) => method.visit(visitors, data, options, chain),
Expand All @@ -54,7 +54,7 @@ impl crate::Visitable for ObjectLiteralMember {
chain: &mut temporary_annex::Annex<crate::Chain>,
) {
match self {
ObjectLiteralMember::SpreadExpression(_, _) => {}
ObjectLiteralMember::Spread(_, _) => {}
ObjectLiteralMember::Shorthand(_, _) => {}
ObjectLiteralMember::Property(_, _, _) => {}
ObjectLiteralMember::Method(method) => method.visit_mut(visitors, data, options, chain),
Expand All @@ -68,20 +68,16 @@ pub type ObjectLiteralMethod = FunctionBase<ObjectLiteralMethodBase>;

impl FunctionBased for ObjectLiteralMethodBase {
type Name = WithComment<PropertyKey<AlwaysPublic>>;
type Header = Option<MethodHeader>;
type Header = MethodHeader;
type Body = Block;

// fn get_chain_variable(this: &FunctionBase<Self>) -> ChainVariable {
// ChainVariable::UnderClassMethod(this.body.1)
// }

fn header_and_name_from_reader(
reader: &mut impl TokenReader<TSXToken, crate::TokenStart>,
state: &mut crate::ParsingState,
options: &ParseOptions,
) -> ParseResult<(Self::Header, Self::Name)> {
Ok((
MethodHeader::optional_from_reader(reader),
MethodHeader::from_reader(reader),
WithComment::<PropertyKey<_>>::from_reader(reader, state, options)?,
))
}
Expand All @@ -93,14 +89,12 @@ impl FunctionBased for ObjectLiteralMethodBase {
options: &crate::ToStringOptions,
depth: u8,
) {
if let Some(ref header) = header {
header.to_string_from_buffer(buf);
}
header.to_string_from_buffer(buf);
name.to_string_from_buffer(buf, options, depth);
}

fn header_left(header: &Self::Header) -> Option<source_map::Start> {
header.as_ref().map(|header| header.get_start())
header.get_start()
}
}

Expand Down Expand Up @@ -129,7 +123,7 @@ impl ASTNode for ObjectLiteral {
buf.push('{');
options.add_gap(buf);
for (at_end, member) in self.members.iter().endiate() {
member.to_string_from_buffer(buf, options, depth + 1);
member.to_string_from_buffer(buf, options, depth);
if !at_end {
buf.push(',');
options.add_gap(buf);
Expand Down Expand Up @@ -170,22 +164,31 @@ impl ASTNode for ObjectLiteralMember {
state: &mut crate::ParsingState,
options: &ParseOptions,
) -> ParseResult<Self> {
if let Some(Token(_, spread_start)) =
reader.conditional_next(|tok| matches!(tok, TSXToken::Spread))
{
// TODO precedence okay?
let expression = Expression::from_reader(reader, state, options)?;
let position = spread_start.union(expression.get_position());
return Ok(Self::Spread(expression, position));
};

// TODO this probably needs with comment here:
let mut header = MethodHeader::optional_from_reader(reader);
let mut header = MethodHeader::from_reader(reader);
// Catch for named get or set :(
let is_named_get_or_set = matches!(
(reader.peek(), &header),
(
Some(Token(TSXToken::OpenParentheses | TSXToken::Colon, _)),
Some(MethodHeader::Get(..) | MethodHeader::Set(..))
MethodHeader::Get(..) | MethodHeader::Set(..)
)
);

let key = if is_named_get_or_set {
// Backtrack allowing `get` to be a key
let (name, position) = match mem::take(&mut header) {
Some(MethodHeader::Get(kw)) => ("get", kw.1),
Some(MethodHeader::Set(kw)) => ("set", kw.1),
MethodHeader::Get(kw) => ("get", kw.1),
MethodHeader::Set(kw) => ("set", kw.1),
_ => unreachable!(),
};
WithComment::None(PropertyKey::Ident(name.to_owned(), position, ()))
Expand All @@ -206,8 +209,7 @@ impl ASTNode for ObjectLiteralMember {
if header.is_some() {
return crate::throw_unexpected_token(reader, &[TSXToken::OpenParentheses]);
}
if matches!(reader.peek(), Some(Token(TSXToken::Comma | TSXToken::CloseBrace, _))) {
// TODO fix
if let Some(Token(TSXToken::Comma | TSXToken::CloseBrace, _)) = reader.peek() {
if let PropertyKey::Ident(name, position, _) = key.get_ast() {
Ok(Self::Shorthand(name, position))
} else {
Expand Down Expand Up @@ -243,7 +245,7 @@ impl ASTNode for ObjectLiteralMember {
Self::Method(func) => {
func.to_string_from_buffer(buf, options, depth);
}
Self::SpreadExpression(spread_expr, _) => {
Self::Spread(spread_expr, _) => {
buf.push_str("...");
spread_expr.to_string_from_buffer(buf, options, depth);
}
Expand All @@ -253,9 +255,7 @@ impl ASTNode for ObjectLiteralMember {
fn get_position(&self) -> &Span {
match self {
Self::Method(method) => method.get_position(),
Self::Shorthand(_, pos)
| Self::Property(_, _, pos)
| Self::SpreadExpression(_, pos) => pos,
Self::Shorthand(_, pos) | Self::Property(_, _, pos) | Self::Spread(_, pos) => pos,
}
}
}
Loading

0 comments on commit 0ece1ad

Please sign in to comment.