aboutsummaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/parser.y b/src/parser.y
index 97a700e..9f532b9 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -93,8 +93,8 @@
%left "::"
%nterm <node> top unit proc call closure var expr statement body
-%nterm <node> vars exprs statements closures
-%nterm <node> opt_vars opt_exprs opt_statements
+%nterm <node> vars exprs statements closures trailing_closure
+%nterm <node> opt_vars opt_exprs opt_statements opt_trailing_closure
%nterm <node> rev_vars rev_exprs rev_closures rev_statements
%nterm <node> let if unop binop construct
@@ -197,6 +197,9 @@ proc
: ID "(" opt_vars ")" body {
$$ = gen_proc($[ID], $[opt_vars], NULL, $[body], src_loc(@$));
}
+ | ID "(" opt_vars ")" ";" {
+ $$ = gen_proc($[ID], $[opt_vars], NULL, NULL, src_loc(@$));
+ }
binop
: expr "+" expr { $$ = gen_binop(AST_ADD, $1, $3, src_loc(@$)); }
@@ -276,8 +279,22 @@ rev_closures
: rev_closures closure { $$ = $2; $2->n = $1; }
| closure
+trailing_closure
+ : "=>" opt_vars ";" { $$ = gen_closure($[opt_vars], NULL, src_loc(@$));}
+
+opt_trailing_closure
+ : trailing_closure
+ | { $$ = NULL; }
+
closures
- : rev_closures { $$ = reverse_ast_list($1); }
+ : rev_closures opt_trailing_closure {
+ if ($[opt_trailing_closure]) {
+ $[opt_trailing_closure]->n = $[rev_closures];
+ $$ = reverse_ast_list($[opt_trailing_closure]);
+ } else {
+ $$ = reverse_ast_list($[rev_closures]);
+ }
+ }
call
: expr "(" opt_exprs ")" ";" {
@@ -307,6 +324,7 @@ statement
: call
| let
| if
+ | body
| ";" { $$ = gen_empty(src_loc(@$)); }
rev_statements