summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 17:57:01 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 17:57:31 +0200
commitf24dabd0897e802d30e8b652f0b633b84c78865b (patch)
tree1047a47b5d8d92c55fdfc8e53a7c515100aeb24b /crates
parent89e0405a5818339179cffba1b16ef09db31dea5e (diff)
downloadrebel-f24dabd0897e802d30e8b652f0b633b84c78865b.tar
rebel-f24dabd0897e802d30e8b652f0b633b84c78865b.zip
rebel-parse: add support for swapped-add-assign operator (`=+`)
Diffstat (limited to 'crates')
-rw-r--r--crates/rebel-parse/src/ast.rs17
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs7
2 files changed, 17 insertions, 7 deletions
diff --git a/crates/rebel-parse/src/ast.rs b/crates/rebel-parse/src/ast.rs
index e3b93ba..88853d7 100644
--- a/crates/rebel-parse/src/ast.rs
+++ b/crates/rebel-parse/src/ast.rs
@@ -55,14 +55,21 @@ pub enum BodyStmt<'a> {
}
impl<'a> BodyStmt<'a> {
- pub(crate) fn assign(dest: TypedExpr<'a>, op: Option<OpBinary>, expr: Expr<'a>) -> Self {
+ pub(crate) fn assign(
+ dest: TypedExpr<'a>,
+ op: Option<OpBinary>,
+ swapped: bool,
+ expr: Expr<'a>,
+ ) -> Self {
match op {
Some(op) => {
let dest_expr = dest.expr.clone();
- BodyStmt::Assign {
- dest,
- expr: Expr::binary(dest_expr, op, expr),
- }
+ let expr = if swapped {
+ Expr::binary(expr, op, dest_expr)
+ } else {
+ Expr::binary(dest_expr, op, expr)
+ };
+ BodyStmt::Assign { dest, expr }
}
None => BodyStmt::Assign { dest, expr },
}
diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs
index 393b12c..aaa40d2 100644
--- a/crates/rebel-parse/src/grammar/recipe.rs
+++ b/crates/rebel-parse/src/grammar/recipe.rs
@@ -27,8 +27,11 @@ peg::parser! {
= body:body_stmt() ++ p(';') { ast::Body(body) }
pub rule body_stmt() -> ast::BodyStmt<'a>
- = dest:typed_expr() op:assign_op() expr:expr() {
- ast::BodyStmt::assign(dest, op, expr)
+ = dest:typed_expr() p2('=', '+') expr:expr() {
+ ast::BodyStmt::assign(dest, Some(Add), true, expr)
+ }
+ / dest:typed_expr() op:assign_op() expr:expr() {
+ ast::BodyStmt::assign(dest, op, false, expr)
}
/ expr:expr() {
ast::BodyStmt::Expr { expr }