From c9d3f7629cfdacededf2a92252e6c9de8a8b75ae Mon Sep 17 00:00:00 2001
From: David Li
Date: Sat, 4 Nov 2017 19:18:49 -0400
Subject: Parse unary operators
---
src/taiga.lalrpop | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
(limited to 'src/taiga.lalrpop')
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> = {
};
ExpressionMul: Box> = {
- "*" => Box::new(e1.join_map(*e2, |v1, v2| {
+ "*" => Box::new(e1.join_map(*e2, |v1, v2| {
ast::Expression::BinOp(ast::BinOp::Mul, Box::new(v1), Box::new(v2))
})),
- "/" => Box::new(e1.join_map(*e2, |v1, v2| {
+ "/" => Box::new(e1.join_map(*e2, |v1, v2| {
ast::Expression::BinOp(ast::BinOp::Div, Box::new(v1), Box::new(v2))
})),
- "//" => Box::new(e1.join_map(*e2, |v1, v2| {
+ "//" => Box::new(e1.join_map(*e2, |v1, v2| {
ast::Expression::BinOp(ast::BinOp::FloorDiv, Box::new(v1), Box::new(v2))
})),
+ => <>,
+};
+
+ExpressionSign: Box> = {
+ "+" => Box::new(WithLocation::new(
+ ast::Expression::UnaryOp(ast::UnaryOp::Pos, e),
+ l, r
+ )),
+ "-" => Box::new(WithLocation::new(
+ ast::Expression::UnaryOp(ast::UnaryOp::Neg, e),
+ l, r
+ )),
=> <>,
};
--
cgit v1.2.3