diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-28 00:26:34 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-28 10:02:14 +0200 |
commit | e9a91ade7eed42f576905facd9acdbe14a3cbac2 (patch) | |
tree | 529f6a7c958a289abbd137eab8ff687ea32223fe /crates/rebel-parse | |
parent | d9bda8ed4ff50ee82608e48a6ab8cdd5680b668c (diff) | |
download | rebel-e9a91ade7eed42f576905facd9acdbe14a3cbac2.tar rebel-e9a91ade7eed42f576905facd9acdbe14a3cbac2.zip |
rebel-parse: allow expression and empty statements
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r-- | crates/rebel-parse/src/ast.rs | 2 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/crates/rebel-parse/src/ast.rs b/crates/rebel-parse/src/ast.rs index 16df2ad..90c02f5 100644 --- a/crates/rebel-parse/src/ast.rs +++ b/crates/rebel-parse/src/ast.rs @@ -21,6 +21,8 @@ pub type Body<'a> = Vec<BodyStmt<'a>>; #[derive(Debug, Clone, PartialEq, Eq)] pub enum BodyStmt<'a> { Assign { dest: TypedExpr<'a>, expr: Expr<'a> }, + Expr { expr: Expr<'a> }, + Empty, } impl<'a> BodyStmt<'a> { diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 6c52367..71c2733 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -19,17 +19,21 @@ peg::parser! { p('{') body:body() p('}') { ast::RecipeStmt::Task { name, params, body } } - / stmt:body_stmt() { + / stmt:body_stmt() p(';') { ast::RecipeStmt::BodyStmt(stmt) } pub rule body() -> ast::Body<'a> - = body:body_stmt()* { body } + = body:body_stmt() ++ p(';') { body } pub rule body_stmt() -> ast::BodyStmt<'a> - = left:typed_expr() op:assign_op() right:expr() p(';') { - ast::BodyStmt::assign(left, op, right) + = dest:typed_expr() op:assign_op() expr:expr() { + ast::BodyStmt::assign(dest, op, expr) } + / expr:expr() { + ast::BodyStmt::Expr { expr } + } + / { ast::BodyStmt::Empty } rule assign_op() -> Option<ast::OpBinary> = p2('+', '=') { Some(Add) } |