From 249ab68e4744aed0a93ce9ff842c9f6fe0e13201 Mon Sep 17 00:00:00 2001
From: David Li
Date: Sun, 5 Nov 2017 21:16:57 -0500
Subject: Parse function declarations
---
src/ast.rs | 18 +++++++++++++++++-
src/taiga.lalrpop | 4 ++++
2 files changed, 21 insertions(+), 1 deletion(-)
(limited to 'src')
diff --git a/src/ast.rs b/src/ast.rs
index d9ce406..8b93e34 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -118,7 +118,9 @@ pub enum DeclarationBody {
ty: WithLocation,
},
Fun {
- ty: Box>,
+ ty: Option>,
+ params: Vec>,
+ body: Box>,
},
}
@@ -142,4 +144,18 @@ impl Declaration {
}
}
}
+
+ pub fn new_fun(name: WithLocation,
+ params: Vec>,
+ type_: Option>,
+ body: Box>) -> Declaration {
+ Declaration {
+ name: name,
+ declaration: DeclarationBody::Fun {
+ ty: type_,
+ params: params,
+ body: body,
+ }
+ }
+ }
}
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop
index aa5e50e..0144aad 100644
--- a/src/taiga.lalrpop
+++ b/src/taiga.lalrpop
@@ -31,6 +31,10 @@ Declaration: Box> = {
Box::new(WithLocation::new(ast::Declaration::new_var(name, None, exp), l, r)),
"type" "=" =>
Box::new(WithLocation::new(ast::Declaration::new_ty(name, ty), l, r)),
+ "function" "(" ")" "=" =>
+ Box::new(WithLocation::new(ast::Declaration::new_fun(name, params, None, body), l, r)),
+ "function" "(" ")" ":" "=" =>
+ Box::new(WithLocation::new(ast::Declaration::new_fun(name, params, Some(ty), body), l, r)),
};
DeclarationsList: Vec> = {
--
cgit v1.2.3