summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2017-11-04 19:38:55 -0400
committerDavid Li <li.davidm96@gmail.com>2017-11-04 19:38:55 -0400
commit13e7a55d3924f77fccf8b97a2373dfb29eba6e5a (patch)
treefac4315ebe041232ffc6fa8ea4171f09bad9ae59 /src
parent9891204b026c7660676f456128c94b01ae7f39cf (diff)
Parse logical operators
Diffstat (limited to 'src')
-rw-r--r--src/ast.rs3
-rw-r--r--src/taiga.lalrpop18
2 files changed, 19 insertions, 2 deletions
diff --git a/src/ast.rs b/src/ast.rs
index ab9493e..4eea431 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -38,6 +38,7 @@ pub struct Program(pub Box<WithLocation<Expression>>);
pub enum UnaryOp {
Pos,
Neg,
+ Not,
}
#[derive(Debug)]
@@ -53,6 +54,8 @@ pub enum BinOp {
Lt,
Ge,
Le,
+ And,
+ Or,
}
#[derive(Debug)]
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop
index 6aedf42..68238eb 100644
--- a/src/taiga.lalrpop
+++ b/src/taiga.lalrpop
@@ -8,10 +8,24 @@ pub Program: ast::Program = {
};
Expression: Box<ast::WithLocation<ast::Expression>> = {
- <e1:Expression> "=" <e2:ExpressionCmp> => Box::new(e1.join_map(*e2, |v1, v2| {
+ <e1:Expression> "&&" <e2:ExpressionEq> => Box::new(e1.join_map(*e2, |v1, v2| {
+ ast::Expression::BinOp(ast::BinOp::And, Box::new(v1), Box::new(v2))
+ })),
+ <e1:Expression> "||" <e2:ExpressionEq> => Box::new(e1.join_map(*e2, |v1, v2| {
+ ast::Expression::BinOp(ast::BinOp::Or, Box::new(v1), Box::new(v2))
+ })),
+ <l: @L> "!" <e: ExpressionEq> <r: @R> => Box::new(WithLocation::new(
+ ast::Expression::UnaryOp(ast::UnaryOp::Not, e),
+ l, r
+ )),
+ <ExpressionEq> => <>,
+};
+
+ExpressionEq: Box<ast::WithLocation<ast::Expression>> = {
+ <e1:ExpressionEq> "=" <e2:ExpressionCmp> => Box::new(e1.join_map(*e2, |v1, v2| {
ast::Expression::BinOp(ast::BinOp::Eq, Box::new(v1), Box::new(v2))
})),
- <e1:Expression> "!=" <e2:ExpressionCmp> => Box::new(e1.join_map(*e2, |v1, v2| {
+ <e1:ExpressionEq> "!=" <e2:ExpressionCmp> => Box::new(e1.join_map(*e2, |v1, v2| {
ast::Expression::BinOp(ast::BinOp::Neq, Box::new(v1), Box::new(v2))
})),
<ExpressionCmp> => <>,