Pattern guards for functions and switch statements #830

Merged
ghallak merged 23 commits from ghallak/232 into master 2021-10-20 17:04:01 +09:00
2 changed files with 8 additions and 2 deletions
Showing only changes of commit 9e85658ca4 - Show all commits

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()).