From 13e7a55d3924f77fccf8b97a2373dfb29eba6e5a Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 4 Nov 2017 19:38:55 -0400 Subject: Parse logical operators --- src/taiga.lalrpop | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/taiga.lalrpop') 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> = { - "=" => Box::new(e1.join_map(*e2, |v1, v2| { + "&&" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::And, Box::new(v1), Box::new(v2)) + })), + "||" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Or, Box::new(v1), Box::new(v2)) + })), + "!" => Box::new(WithLocation::new( + ast::Expression::UnaryOp(ast::UnaryOp::Not, e), + l, r + )), + => <>, +}; + +ExpressionEq: Box> = { + "=" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Eq, 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::Neq, Box::new(v1), Box::new(v2)) })), => <>, -- cgit v1.2.3