diff options
Diffstat (limited to 'src/taiga.lalrpop')
-rw-r--r-- | src/taiga.lalrpop | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop index 0182a04..6bf750d 100644 --- a/src/taiga.lalrpop +++ b/src/taiga.lalrpop @@ -18,15 +18,27 @@ Expression: Box<ast::WithLocation<ast::Expression>> = { }; ExpressionMul: Box<ast::WithLocation<ast::Expression>> = { - <e1:ExpressionMul> "*" <e2:ExpressionBase> => Box::new(e1.join_map(*e2, |v1, v2| { + <e1:ExpressionMul> "*" <e2:ExpressionSign> => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Mul, Box::new(v1), Box::new(v2)) })), - <e1:ExpressionMul> "/" <e2:ExpressionBase> => Box::new(e1.join_map(*e2, |v1, v2| { + <e1:ExpressionMul> "/" <e2:ExpressionSign> => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Div, Box::new(v1), Box::new(v2)) })), - <e1:ExpressionMul> "//" <e2:ExpressionBase> => Box::new(e1.join_map(*e2, |v1, v2| { + <e1:ExpressionMul> "//" <e2:ExpressionSign> => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::FloorDiv, Box::new(v1), Box::new(v2)) })), + <ExpressionSign> => <>, +}; + +ExpressionSign: Box<ast::WithLocation<ast::Expression>> = { + <l: @L> "+" <e: ExpressionBase> <r: @R> => Box::new(WithLocation::new( + ast::Expression::UnaryOp(ast::UnaryOp::Pos, e), + l, r + )), + <l: @L> "-" <e: ExpressionBase> <r: @R> => Box::new(WithLocation::new( + ast::Expression::UnaryOp(ast::UnaryOp::Neg, e), + l, r + )), <ExpressionBase> => <>, }; |