Add case guards to parser

This commit is contained in:
Gaith Hallak 2021-08-25 12:12:00 +03:00
parent 20cab3ae57
commit 9e85658ca4
2 changed files with 8 additions and 2 deletions

View File

@ -282,9 +282,14 @@ stmt() ->
, {else, keyword(else), body()} , {else, keyword(else), body()}
])). ])).
branch() -> branch() -> choice(unguarded_branch(), guarded_branch()).
unguarded_branch() ->
?RULE(pattern(), keyword('=>'), body(), {'case', _2, _1, _3}). ?RULE(pattern(), keyword('=>'), body(), {'case', _2, _1, _3}).
guarded_branch() ->
?RULE(pattern(), tok('|'), expr(), keyword('=>'), body(), {'case', _4, _1, _3, _5}).
pattern() -> pattern() ->
?LET_P(E, expr(), parse_pattern(E)). ?LET_P(E, expr(), parse_pattern(E)).

View File

@ -145,7 +145,8 @@
-type stmt() :: letbind() -type stmt() :: letbind()
| expr(). | expr().
-type alt() :: {'case', ann(), pat(), expr()}. -type alt() :: {'case', ann(), pat(), expr()}
| {'case', ann(), pat(), expr(), expr()}.
-type lvalue() :: nonempty_list(elim()). -type lvalue() :: nonempty_list(elim()).