Skip to content

Commit

Permalink
Merge pull request #121 from kyleect/grammar-file-cleanup-2
Browse files Browse the repository at this point in the history
More grammar file clean up
  • Loading branch information
kyleect authored Dec 31, 2023
2 parents 6416da3 + ccba2f0 commit 5355556
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions res/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ grammar<'err>(
errors: &'err mut Vec<ParseError<usize, lexer::Token, ErrorS>>
);

pub Program: ast::Program = <stmts:DeclS*> => ast::Program { <> };
pub Program: ast::Program = <stmts:Spanned<Decl>*> => ast::Program { <> };

// Declarations
DeclS = Spanned<Decl>;

Decl = {
DeclClass,
DeclFn,
DeclLetVar,
Stmt,
}

DeclClass: ast::Stmt =
DeclClass: ast::Stmt = <class:StmtClass> => ast::Stmt::Class(<>);

StmtClass: ast::StmtClass =
"class" <name:identifier> <super_:("extends" <Spanned<ExprIdentifier>>)?> "{"
<fields:("let" <Spanned<StmtAssign>>)*>
<fields:(<Spanned<StmtAssign>>)*>
<methods:(<Spanned<StmtFn>>)*>
"}" =>
ast::Stmt::Class(ast::StmtClass { <> });
ast::StmtClass { <> };

DeclFn: ast::Stmt = <function:StmtFn> => ast::Stmt::Fn(<>);

Expand Down Expand Up @@ -67,10 +67,10 @@ StmtFn: ast::StmtFn = {
}
}

DeclLetVar: ast::Stmt = "let" <assign:StmtAssign> =>
DeclLetVar: ast::Stmt = <assign:StmtAssign> =>
ast::Stmt::Assign(<>);

StmtAssign: ast::StmtAssign = <name:identifier> <value:("=" <ExprS>)?> ";" => ast::StmtAssign {
StmtAssign: ast::StmtAssign = "let" <name:identifier> <value:("=" <ExprS>)?> ";" => ast::StmtAssign {
identifier: ast::Identifier {
name,
depth: None
Expand Down Expand Up @@ -129,7 +129,7 @@ StmtSimple = {

StmtBlock: ast::Stmt = StmtBlockInternal => ast::Stmt::Block(<>);

StmtBlockInternal: ast::StmtBlock = "{" <stmts:DeclS*> "}" =>
StmtBlockInternal: ast::StmtBlock = "{" <stmts:Spanned<Decl>*> "}" =>
ast::StmtBlock { <> };

StmtExpr: ast::Stmt = <value:ExprS> ";" =>
Expand Down

0 comments on commit 5355556

Please sign in to comment.