Skip to content

Commit

Permalink
Simplify ExprStmt parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlamonster committed Oct 30, 2023
1 parent 95394c6 commit 158793b
Show file tree
Hide file tree
Showing 2 changed files with 725 additions and 574 deletions.
19 changes: 4 additions & 15 deletions compiler/src/passes/parse/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,15 @@ Type: Type = {
Expr = ExprStmt;

ExprStmt: Expr<&'input str> = {
// TODO yeet this?
"let" <mutable:"mut"?> <sym:Ident> "=" <bnd:ExprLogicalOr> ";" => Expr::Let {
"let" <mutable:"mut"?> <sym:Ident> "=" <bnd:ExprLogicalOr> ";" <bdy:ExprStmt?> => Expr::Let {
sym,
mutable: mutable.is_some(),
bnd: Box::new(bnd),
bdy: Box::new(Expr::Lit { val: Lit::Unit }),
},
"let" <mutable:"mut"?> <sym:Ident> "=" <bnd:ExprLogicalOr> ";" <bdy:ExprStmt> => Expr::Let {
sym,
mutable: mutable.is_some(),
bnd: Box::new(bnd),
bdy: Box::new(bdy),
},
<stmt:ExprInStmt> ";" => Expr::Seq {
stmt: Box::new(stmt),
cnt: Box::new(Expr::Lit { val: Lit::Unit }),
bdy: Box::new(bdy.unwrap_or(Expr::Lit { val: Lit::Unit })),
},
<stmt:ExprInStmt> ";" <cnt:ExprStmt> => Expr::Seq {
<stmt:ExprInStmt> ";" <cnt:ExprStmt?> => Expr::Seq {
stmt: Box::new(stmt),
cnt: Box::new(cnt),
cnt: Box::new(cnt.unwrap_or(Expr::Lit { val: Lit::Unit })),
},
ExprInStmt,
}
Expand Down
Loading

0 comments on commit 158793b

Please sign in to comment.