Skip to content

Commit

Permalink
Simplify If parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlamonster committed Oct 30, 2023
1 parent 564bcd5 commit 95394c6
Show file tree
Hide file tree
Showing 2 changed files with 1,171 additions and 973 deletions.
9 changes: 2 additions & 7 deletions compiler/src/passes/parse/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,10 @@ ExprInStmt: Expr<&'input str> = {
sym,
bnd: Box::new(bnd),
},
"if" <cnd:ExprLogicalOr> "{" <thn:Expr> "}" "else" "{" <els:Expr> "}" => Expr::If {
"if" <cnd:ExprLogicalOr> "{" <thn:Expr> "}" <els:("else" "{" <Expr> "}")?> => Expr::If {
cnd: Box::new(cnd),
thn: Box::new(thn),
els: Box::new(els),
},
"if" <cnd:ExprLogicalOr> "{" <thn:Expr> "}" => Expr::If {
cnd: Box::new(cnd),
thn: Box::new(thn),
els: Box::new(Expr::Lit { val: Lit::Unit }),
els: Box::new(els.unwrap_or(Expr::Lit { val: Lit::Unit })),
},
"loop" "{" <bdy:Expr> "}" => Expr::Loop {
bdy: Box::new(bdy),
Expand Down
Loading

0 comments on commit 95394c6

Please sign in to comment.