diff options
-rw-r--r-- | src/ast.rs | 18 | ||||
-rw-r--r-- | src/taiga.lalrpop | 4 |
2 files changed, 21 insertions, 1 deletions
@@ -118,7 +118,9 @@ pub enum DeclarationBody { ty: WithLocation<Ty>, }, Fun { - ty: Box<WithLocation<Ty>>, + ty: Option<WithLocation<Ty>>, + params: Vec<WithLocation<RecordField>>, + body: Box<WithLocation<Expression>>, }, } @@ -142,4 +144,18 @@ impl Declaration { } } } + + pub fn new_fun(name: WithLocation<String>, + params: Vec<WithLocation<RecordField>>, + type_: Option<WithLocation<Ty>>, + body: Box<WithLocation<Expression>>) -> 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<WithLocation<ast::Declaration>> = { 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)), + <l: @L> "function" <name: Name> "(" <params: RecordFields> ")" "=" <body: Expression> <r: @R> => + Box::new(WithLocation::new(ast::Declaration::new_fun(name, params, None, body), l, r)), + <l: @L> "function" <name: Name> "(" <params: RecordFields> ")" ":" <ty: Ty> "=" <body: Expression> <r: @R> => + Box::new(WithLocation::new(ast::Declaration::new_fun(name, params, Some(ty), body), l, r)), }; DeclarationsList: Vec<WithLocation<ast::Declaration>> = { |