Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): Support pattern matching "or" patterns #1173

Merged
merged 10 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
420 changes: 186 additions & 234 deletions compiler/src/middle_end/linearize.re

Large diffs are not rendered by default.

1,565 changes: 843 additions & 722 deletions compiler/src/middle_end/matchcomp.re

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions compiler/src/parsing/parser.messages
Original file line number Diff line number Diff line change
Expand Up @@ -3862,6 +3862,32 @@ program: LET LPAREN WASMI64 COMMA EOL WHILE
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
## In state 5, spurious reduction of production eols -> nonempty_list(eol)
##
program: LET NUMBER_INT PIPE WHILE
##
## Ends in an error in state: 345.
##
## pattern -> pattern PIPE . pattern [ WHEN THICKARROW RPAREN RBRACK RBRACE PIPE EQUAL EOL COMMA COLON ]
## pattern -> pattern PIPE . eols pattern [ WHEN THICKARROW RPAREN RBRACK RBRACE PIPE EQUAL EOL COMMA COLON ]
##
## The known suffix of the stack is as follows:
## pattern PIPE
##
program: LET NUMBER_INT PIPE EOL WHILE
##
## Ends in an error in state: 404.
##
## pattern -> pattern PIPE eols . pattern [ WHEN THICKARROW RPAREN RBRACK RBRACE PIPE EQUAL EOL COMMA COLON ]
##
## The known suffix of the stack is as follows:
## pattern PIPE eols
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
## In state 5, spurious reduction of production eols -> nonempty_list(eol)
##

Expected a pattern.

Expand Down
1 change: 1 addition & 0 deletions compiler/src/parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ pattern:
| type_id { Pat.construct ~loc:(to_loc $loc) $1 [] }
| lbrack rbrack { Pat.list ~loc:(to_loc $loc) [] }
| lbrack lseparated_nonempty_list(comma, list_item_pat) comma? rbrack { Pat.list ~loc:(to_loc $loc) $2 }
| pattern pipe_op opt_eols pattern { Pat.or_ ~loc:(to_loc $loc) $1 $4 }

list_item_pat:
| ELLIPSIS pattern { ListSpread ($2, to_loc $loc) }
Expand Down
Loading