From 58f30a0ce9e8bb0dde99edcbbaf8e1b7757e2ee6 Mon Sep 17 00:00:00 2001 From: David Li Date: Sun, 5 Nov 2017 21:32:18 -0500 Subject: Parse empty records/function parameter lists --- src/taiga.lalrpop | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop index 0144aad..afa6433 100644 --- a/src/taiga.lalrpop +++ b/src/taiga.lalrpop @@ -7,21 +7,30 @@ pub Program: ast::Program = { Expression => ast::Program(<>), }; -RecordFields: Vec> = { - ":" "," => { +FieldList: Vec> = { + ":" "," => { let mut rest = rest; rest.push(WithLocation::new(ast::RecordField::new(n, v), l, r)); rest }, ":" "," => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)], ":" => vec![WithLocation::new(ast::RecordField::new(n, v), l, r)], - "" => vec![], +}; + +RecordFields: WithLocation>> = { + "{" "}" => WithLocation::new(v, l, r), + "{" "}" => WithLocation::new(vec![], l, r), +}; + +Parameters: WithLocation>> = { + "(" ")" => WithLocation::new(v, l, r), + "(" ")" => WithLocation::new(vec![], l, r), }; Ty: WithLocation = { => <>.map(|v| ast::Ty::Name(v)), "array" "of" => <>.map(|v| ast::Ty::Array(Box::new(ast::Ty::Name(v)))), - "{" "}" => WithLocation::new(ast::Ty::Record(v), l, r), + => <>.map(|v| ast::Ty::Record(v)), }; Declaration: Box> = { @@ -31,10 +40,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)), + "function" "=" => + Box::new(WithLocation::new(ast::Declaration::new_fun(name, params.value, None, body), l, r)), + "function" ":" "=" => + Box::new(WithLocation::new(ast::Declaration::new_fun(name, params.value, Some(ty), body), l, r)), }; DeclarationsList: Vec> = { -- cgit v1.2.3