From 9f393b2eb7b3fb8f1924e80095bad3384049cc67 Mon Sep 17 00:00:00 2001
From: David Li
Date: Sat, 4 Nov 2017 20:15:20 -0400
Subject: Parse let expressions
---
src/taiga.lalrpop | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'src/taiga.lalrpop')
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop
index be47147..851cb24 100644
--- a/src/taiga.lalrpop
+++ b/src/taiga.lalrpop
@@ -7,6 +7,19 @@ pub Program: ast::Program = {
Expression => ast::Program(<>),
};
+VarDec: Box> =
+ "var" "=" =>
+ Box::new(WithLocation::new(ast::VarDec::new(name, None, exp), l, r));
+
+DeclarationsList: Vec> = {
+ => {
+ let mut h = h;
+ h.push(*t);
+ h
+ },
+ => vec![*<>],
+};
+
Expression: Box> = {
"&&" => Box::new(e1.join_map(*e2, |v1, v2| {
ast::Expression::BinOp(ast::BinOp::And, Box::new(v1), Box::new(v2))
@@ -87,6 +100,8 @@ ExpressionBase: Box> = {
String => Box::new(<>.map(|v| ast::Expression::String(v))),
Name => Box::new(<>.map(|v| ast::Expression::Name(v))),
Spanned => Box::new(<>.map(|v| ast::Expression::Nil)),
+ "let" "in" "end" =>
+ Box::new(WithLocation::new(ast::Expression::Let(d, e), l, r)),
"(" ")" => <>,
};
@@ -102,6 +117,10 @@ Spanned: WithLocation = {
match {
"nil",
+ "var",
+ "let",
+ "in",
+ "end",
}
else {
r"[[:alpha:]_][[:alpha:]_0-9]*",
--
cgit v1.2.3