summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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> => <>,