Skip to content

Commit 2caa654

Browse files
authored
Merge pull request #3287 from ydah/allow-patterns-with-and-or-comma
[Bug #20785] Allow `, and` and `, or` after patterns
2 parents ff50a14 + 71c9102 commit 2caa654

File tree

3 files changed

+251
-78
lines changed

3 files changed

+251
-78
lines changed

src/prism.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13060,14 +13060,6 @@ match4(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2,
1306013060
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4);
1306113061
}
1306213062

13063-
/**
13064-
* Returns true if the current token is any of the six given types.
13065-
*/
13066-
static inline bool
13067-
match6(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2, pm_token_type_t type3, pm_token_type_t type4, pm_token_type_t type5, pm_token_type_t type6) {
13068-
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4) || match1(parser, type5) || match1(parser, type6);
13069-
}
13070-
1307113063
/**
1307213064
* Returns true if the current token is any of the seven given types.
1307313065
*/
@@ -13084,6 +13076,14 @@ match8(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2,
1308413076
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4) || match1(parser, type5) || match1(parser, type6) || match1(parser, type7) || match1(parser, type8);
1308513077
}
1308613078

13079+
/**
13080+
* Returns true if the current token is any of the nine given types.
13081+
*/
13082+
static inline bool
13083+
match9(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2, pm_token_type_t type3, pm_token_type_t type4, pm_token_type_t type5, pm_token_type_t type6, pm_token_type_t type7, pm_token_type_t type8, pm_token_type_t type9) {
13084+
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4) || match1(parser, type5) || match1(parser, type6) || match1(parser, type7) || match1(parser, type8) || match1(parser, type9);
13085+
}
13086+
1308713087
/**
1308813088
* If the current token is of the specified type, lex forward by one token and
1308913089
* return true. Otherwise, return false. For example:
@@ -17608,7 +17608,7 @@ parse_pattern(pm_parser_t *parser, pm_constant_id_list_t *captures, uint8_t flag
1760817608
// Gather up all of the patterns into the list.
1760917609
while (accept1(parser, PM_TOKEN_COMMA)) {
1761017610
// Break early here in case we have a trailing comma.
17611-
if (match6(parser, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE, PM_TOKEN_EOF)) {
17611+
if (match9(parser, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_PARENTHESIS_RIGHT, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE, PM_TOKEN_EOF,PM_TOKEN_KEYWORD_AND, PM_TOKEN_KEYWORD_OR)) {
1761217612
node = (pm_node_t *) pm_implicit_rest_node_create(parser, &parser->previous);
1761317613
pm_node_list_append(&nodes, node);
1761417614
trailing_rest = true;

test/prism/fixtures/patterns.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,8 @@ foo => Object[{x:}]
212212

213213
case (); in [_a, _a]; end
214214
case (); in [{a:1}, {a:2}]; end
215+
216+
a in b, and c
217+
a in b, or c
218+
(a in b,) and c
219+
(a in b,) or c

0 commit comments

Comments
 (0)