Skip to content

Commit 0fb29c4

Browse files
authored
feat(compiler): Support pattern matching "or" patterns (#1173)
* feat(compiler): Support pattern matching "or" patterns * Add new error states * or tests * Snapshots * Add clarifying comments * Remove Either implementation * Remove inaccurate comment * Note impossible case * Reference optimization issue * Add a few destructuring smoke tests
1 parent 8261e73 commit 0fb29c4

File tree

52 files changed

+12366
-5458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+12366
-5458
lines changed

compiler/src/middle_end/linearize.re

Lines changed: 186 additions & 234 deletions
Large diffs are not rendered by default.

compiler/src/middle_end/matchcomp.re

Lines changed: 843 additions & 722 deletions
Large diffs are not rendered by default.

compiler/src/parsing/parser.messages

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,6 +3862,32 @@ program: LET LPAREN WASMI64 COMMA EOL WHILE
38623862
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
38633863
## In state 5, spurious reduction of production eols -> nonempty_list(eol)
38643864
##
3865+
program: LET NUMBER_INT PIPE WHILE
3866+
##
3867+
## Ends in an error in state: 345.
3868+
##
3869+
## pattern -> pattern PIPE . pattern [ WHEN THICKARROW RPAREN RBRACK RBRACE PIPE EQUAL EOL COMMA COLON ]
3870+
## pattern -> pattern PIPE . eols pattern [ WHEN THICKARROW RPAREN RBRACK RBRACE PIPE EQUAL EOL COMMA COLON ]
3871+
##
3872+
## The known suffix of the stack is as follows:
3873+
## pattern PIPE
3874+
##
3875+
program: LET NUMBER_INT PIPE EOL WHILE
3876+
##
3877+
## Ends in an error in state: 404.
3878+
##
3879+
## pattern -> pattern PIPE eols . pattern [ WHEN THICKARROW RPAREN RBRACK RBRACE PIPE EQUAL EOL COMMA COLON ]
3880+
##
3881+
## The known suffix of the stack is as follows:
3882+
## pattern PIPE eols
3883+
##
3884+
## WARNING: This example involves spurious reductions.
3885+
## This implies that, although the LR(1) items shown above provide an
3886+
## accurate view of the past (what has been recognized so far), they
3887+
## may provide an INCOMPLETE view of the future (what was expected next).
3888+
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
3889+
## In state 5, spurious reduction of production eols -> nonempty_list(eol)
3890+
##
38653891

38663892
Expected a pattern.
38673893

compiler/src/parsing/parser.mly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ pattern:
250250
| type_id { Pat.construct ~loc:(to_loc $loc) $1 [] }
251251
| lbrack rbrack { Pat.list ~loc:(to_loc $loc) [] }
252252
| lbrack lseparated_nonempty_list(comma, list_item_pat) comma? rbrack { Pat.list ~loc:(to_loc $loc) $2 }
253+
| pattern pipe_op opt_eols pattern { Pat.or_ ~loc:(to_loc $loc) $1 $4 }
253254

254255
list_item_pat:
255256
| ELLIPSIS pattern { ListSpread ($2, to_loc $loc) }

0 commit comments

Comments
 (0)