[ruby/prism] [Bug #20785] Allow , and
and , or
after patterns
Partially: https://bugs.ruby-lang.org/issues/20785 https://github.com/ruby/prism/commit/71c9102d02
This commit is contained in:
parent
0dc35f0d30
commit
f6e0a037aa
Notes:
git
2024-12-16 15:51:41 +00:00
@ -13106,14 +13106,6 @@ match4(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2,
|
||||
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current token is any of the six given types.
|
||||
*/
|
||||
static inline bool
|
||||
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) {
|
||||
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4) || match1(parser, type5) || match1(parser, type6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current token is any of the seven given types.
|
||||
*/
|
||||
@ -13130,6 +13122,14 @@ match8(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2,
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current token is any of the nine given types.
|
||||
*/
|
||||
static inline bool
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the current token is of the specified type, lex forward by one token and
|
||||
* return true. Otherwise, return false. For example:
|
||||
@ -17658,7 +17658,7 @@ parse_pattern(pm_parser_t *parser, pm_constant_id_list_t *captures, uint8_t flag
|
||||
// Gather up all of the patterns into the list.
|
||||
while (accept1(parser, PM_TOKEN_COMMA)) {
|
||||
// Break early here in case we have a trailing comma.
|
||||
if (match6(parser, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE, PM_TOKEN_EOF)) {
|
||||
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)) {
|
||||
node = (pm_node_t *) pm_implicit_rest_node_create(parser, &parser->previous);
|
||||
pm_node_list_append(&nodes, node);
|
||||
trailing_rest = true;
|
||||
|
@ -212,3 +212,8 @@ foo => Object[{x:}]
|
||||
|
||||
case (); in [_a, _a]; end
|
||||
case (); in [{a:1}, {a:2}]; end
|
||||
|
||||
a in b, and c
|
||||
a in b, or c
|
||||
(a in b,) and c
|
||||
(a in b,) or c
|
||||
|
Loading…
x
Reference in New Issue
Block a user