summaryrefslogtreecommitdiff
path: root/src/taiga.lalrpop
diff options
context:
space:
mode:
Diffstat (limited to 'src/taiga.lalrpop')
-rw-r--r--src/taiga.lalrpop19
1 files changed, 19 insertions, 0 deletions
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<WithLocation<ast::VarDec>> =
+ <l: @L> "var" <name: Name> "=" <exp: Expression> <r: @R> =>
+ Box::new(WithLocation::new(ast::VarDec::new(name, None, exp), l, r));
+
+DeclarationsList: Vec<WithLocation<ast::VarDec>> = {
+ <h: DeclarationsList> <t: VarDec> => {
+ let mut h = h;
+ h.push(*t);
+ h
+ },
+ <VarDec> => vec![*<>],
+};
+
Expression: Box<ast::WithLocation<ast::Expression>> = {
<e1:Expression> "&&" <e2:ExpressionEq> => 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<ast::WithLocation<ast::Expression>> = {
String => Box::new(<>.map(|v| ast::Expression::String(v))),
Name => Box::new(<>.map(|v| ast::Expression::Name(v))),
Spanned<r"nil"> => Box::new(<>.map(|v| ast::Expression::Nil)),
+ <l: @L> "let" <d: DeclarationsList> "in" <e: Expression> "end" <r: @R> =>
+ Box::new(WithLocation::new(ast::Expression::Let(d, e), l, r)),
"(" <Expression> ")" => <>,
};
@@ -102,6 +117,10 @@ Spanned<T>: WithLocation<T> = {
match {
"nil",
+ "var",
+ "let",
+ "in",
+ "end",
}
else {
r"[[:alpha:]_][[:alpha:]_0-9]*",