diff options
| author | ydah <t.yudai92@gmail.com> | 2024-12-04 15:32:55 +0900 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-12-16 10:51:22 -0500 |
| commit | f6e0a037aa21bd90830cecc397c16918890d76a2 (patch) | |
| tree | f90bc12cfc5890d70e82f66b9c658e058ecc48b5 | |
| parent | 0dc35f0d3027413d7fd7f73d6be1d7ea99cf156e (diff) | |
[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
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12358
| -rw-r--r-- | prism/prism.c | 18 | ||||
| -rw-r--r-- | test/prism/fixtures/patterns.txt | 5 |
2 files changed, 14 insertions, 9 deletions
diff --git a/prism/prism.c b/prism/prism.c index f53e0a861e..3c5a5eda85 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -13107,14 +13107,6 @@ match4(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2, } /** - * 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. */ static inline bool @@ -13131,6 +13123,14 @@ match8(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2, } /** + * 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; diff --git a/test/prism/fixtures/patterns.txt b/test/prism/fixtures/patterns.txt index 5b3bc49652..f4f3489e4d 100644 --- a/test/prism/fixtures/patterns.txt +++ b/test/prism/fixtures/patterns.txt @@ -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 |
