summaryrefslogtreecommitdiff
path: root/src/taiga.lalrpop
diff options
context:
space:
mode:
Diffstat (limited to 'src/taiga.lalrpop')
-rw-r--r--src/taiga.lalrpop34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop
index 851cb24..aa5e50e 100644
--- a/src/taiga.lalrpop
+++ b/src/taiga.lalrpop
@@ -7,17 +7,39 @@ pub Program: ast::Program = {
Expression => ast::Program(<>),
};
-VarDec: Box<WithLocation<ast::VarDec>> =
+RecordFields: Vec<WithLocation<ast::RecordField>> = {
+ <l: @L> <n:Name> ":" <v:Name> <r: @R> "," <rest: RecordFields> => {
+ let mut rest = rest;
+ rest.push(WithLocation::new(ast::RecordField::new(n, v), l, r));
+ rest
+ },
+ <l: @L> <n:Name> ":" <v:Name> <r: @R> "," => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)],
+ <l: @L> <n:Name> ":" <v:Name> <r: @R> => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)],
+ "" => vec![],
+};
+
+Ty: WithLocation<ast::Ty> = {
+ <Name> => <>.map(|v| ast::Ty::Name(v)),
+ "array" "of" <Name> => <>.map(|v| ast::Ty::Array(Box::new(ast::Ty::Name(v)))),
+ <l: @L> "{" <v: RecordFields> "}" <r: @R> => WithLocation::new(ast::Ty::Record(v), l, r),
+};
+
+Declaration: Box<WithLocation<ast::Declaration>> = {
+ <l: @L> "var" <name: Name> ":" <ty: Ty> "=" <exp: Expression> <r: @R> =>
+ Box::new(WithLocation::new(ast::Declaration::new_var(name, Some(ty), exp), l, r)),
<l: @L> "var" <name: Name> "=" <exp: Expression> <r: @R> =>
- Box::new(WithLocation::new(ast::VarDec::new(name, None, exp), l, r));
+ Box::new(WithLocation::new(ast::Declaration::new_var(name, None, exp), l, r)),
+ <l: @L> "type" <name: Name> "=" <ty: Ty> <r: @R> =>
+ Box::new(WithLocation::new(ast::Declaration::new_ty(name, ty), l, r)),
+};
-DeclarationsList: Vec<WithLocation<ast::VarDec>> = {
- <h: DeclarationsList> <t: VarDec> => {
+DeclarationsList: Vec<WithLocation<ast::Declaration>> = {
+ <h: DeclarationsList> <t: Declaration> => {
let mut h = h;
h.push(*t);
h
},
- <VarDec> => vec![*<>],
+ <Declaration> => vec![*<>],
};
Expression: Box<ast::WithLocation<ast::Expression>> = {
@@ -121,6 +143,8 @@ match {
"let",
"in",
"end",
+ "type",
+ "function",
}
else {
r"[[:alpha:]_][[:alpha:]_0-9]*",