diff options
| author | Haldun Bayhantopcu <haldun@github.com> | 2023-11-21 18:22:14 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-11-21 17:22:18 +0000 |
| commit | f397650cda4e99a8eaf710ac5bcf73da960dc30b (patch) | |
| tree | ff25465f22c7b2df6c35cd0078f758d64ebef164 | |
| parent | 91685c01d3de0b01c0f531917100e2458acaa2c6 (diff) | |
[ruby/prism] Fix lex_state_beg_p
(https://github.com/ruby/prism/pull/1591)
https://github.com/ruby/prism/commit/46b8576dd0
| -rw-r--r-- | prism/prism.c | 2 | ||||
| -rw-r--r-- | test/prism/fixtures/methods.txt | 8 | ||||
| -rw-r--r-- | test/prism/snapshots/methods.txt | 222 |
3 files changed, 203 insertions, 29 deletions
diff --git a/prism/prism.c b/prism/prism.c index ccb007ffef..b6be29832f 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -415,7 +415,7 @@ lex_state_ignored_p(pm_parser_t *parser) { static inline bool lex_state_beg_p(pm_parser_t *parser) { - return lex_state_p(parser, PM_LEX_STATE_BEG_ANY) || (parser->lex_state == (PM_LEX_STATE_ARG | PM_LEX_STATE_LABELED)); + return lex_state_p(parser, PM_LEX_STATE_BEG_ANY) || ((parser->lex_state & (PM_LEX_STATE_ARG | PM_LEX_STATE_LABELED)) == (PM_LEX_STATE_ARG | PM_LEX_STATE_LABELED)); } static inline bool diff --git a/test/prism/fixtures/methods.txt b/test/prism/fixtures/methods.txt index 8cdf3ddaee..2a501e8ecf 100644 --- a/test/prism/fixtures/methods.txt +++ b/test/prism/fixtures/methods.txt @@ -168,3 +168,11 @@ foo = 1 def foo.bar; end def f(*); [*]; end + +def f x:-a; end + +def f x:+a; end + +def f x:!a; end + +def foo x:%(xx); end diff --git a/test/prism/snapshots/methods.txt b/test/prism/snapshots/methods.txt index ce23a28248..836b67db6a 100644 --- a/test/prism/snapshots/methods.txt +++ b/test/prism/snapshots/methods.txt @@ -1,8 +1,8 @@ -@ ProgramNode (location: (1,0)-(170,18)) +@ ProgramNode (location: (1,0)-(178,20)) ├── locals: [:a, :c, :foo] └── statements: - @ StatementsNode (location: (1,0)-(170,18)) - └── body: (length: 63) + @ StatementsNode (location: (1,0)-(178,20)) + └── body: (length: 67) ├── @ DefNode (location: (1,0)-(2,3)) │ ├── name: :foo │ ├── name_loc: (1,4)-(1,7) = "foo" @@ -1649,37 +1649,203 @@ │ ├── rparen_loc: ∅ │ ├── equal_loc: ∅ │ └── end_keyword_loc: (168,13)-(168,16) = "end" - └── @ DefNode (location: (170,0)-(170,18)) - ├── name: :f - ├── name_loc: (170,4)-(170,5) = "f" + ├── @ DefNode (location: (170,0)-(170,18)) + │ ├── name: :f + │ ├── name_loc: (170,4)-(170,5) = "f" + │ ├── receiver: ∅ + │ ├── parameters: + │ │ @ ParametersNode (location: (170,6)-(170,7)) + │ │ ├── requireds: (length: 0) + │ │ ├── optionals: (length: 0) + │ │ ├── rest: + │ │ │ @ RestParameterNode (location: (170,6)-(170,7)) + │ │ │ ├── name: ∅ + │ │ │ ├── name_loc: ∅ + │ │ │ └── operator_loc: (170,6)-(170,7) = "*" + │ │ ├── posts: (length: 0) + │ │ ├── keywords: (length: 0) + │ │ ├── keyword_rest: ∅ + │ │ └── block: ∅ + │ ├── body: + │ │ @ StatementsNode (location: (170,10)-(170,13)) + │ │ └── body: (length: 1) + │ │ └── @ ArrayNode (location: (170,10)-(170,13)) + │ │ ├── elements: (length: 1) + │ │ │ └── @ SplatNode (location: (170,11)-(170,12)) + │ │ │ ├── operator_loc: (170,11)-(170,12) = "*" + │ │ │ └── expression: ∅ + │ │ ├── opening_loc: (170,10)-(170,11) = "[" + │ │ └── closing_loc: (170,12)-(170,13) = "]" + │ ├── locals: [:*] + │ ├── def_keyword_loc: (170,0)-(170,3) = "def" + │ ├── operator_loc: ∅ + │ ├── lparen_loc: (170,5)-(170,6) = "(" + │ ├── rparen_loc: (170,7)-(170,8) = ")" + │ ├── equal_loc: ∅ + │ └── end_keyword_loc: (170,15)-(170,18) = "end" + ├── @ DefNode (location: (172,0)-(172,15)) + │ ├── name: :f + │ ├── name_loc: (172,4)-(172,5) = "f" + │ ├── receiver: ∅ + │ ├── parameters: + │ │ @ ParametersNode (location: (172,6)-(172,10)) + │ │ ├── requireds: (length: 0) + │ │ ├── optionals: (length: 0) + │ │ ├── rest: ∅ + │ │ ├── posts: (length: 0) + │ │ ├── keywords: (length: 1) + │ │ │ └── @ OptionalKeywordParameterNode (location: (172,6)-(172,10)) + │ │ │ ├── name: :x + │ │ │ ├── name_loc: (172,6)-(172,8) = "x:" + │ │ │ └── value: + │ │ │ @ CallNode (location: (172,8)-(172,10)) + │ │ │ ├── receiver: + │ │ │ │ @ CallNode (location: (172,9)-(172,10)) + │ │ │ │ ├── receiver: ∅ + │ │ │ │ ├── call_operator_loc: ∅ + │ │ │ │ ├── message_loc: (172,9)-(172,10) = "a" + │ │ │ │ ├── opening_loc: ∅ + │ │ │ │ ├── arguments: ∅ + │ │ │ │ ├── closing_loc: ∅ + │ │ │ │ ├── block: ∅ + │ │ │ │ ├── flags: variable_call + │ │ │ │ └── name: :a + │ │ │ ├── call_operator_loc: ∅ + │ │ │ ├── message_loc: (172,8)-(172,9) = "-" + │ │ │ ├── opening_loc: ∅ + │ │ │ ├── arguments: ∅ + │ │ │ ├── closing_loc: ∅ + │ │ │ ├── block: ∅ + │ │ │ ├── flags: ∅ + │ │ │ └── name: :-@ + │ │ ├── keyword_rest: ∅ + │ │ └── block: ∅ + │ ├── body: ∅ + │ ├── locals: [:x] + │ ├── def_keyword_loc: (172,0)-(172,3) = "def" + │ ├── operator_loc: ∅ + │ ├── lparen_loc: ∅ + │ ├── rparen_loc: ∅ + │ ├── equal_loc: ∅ + │ └── end_keyword_loc: (172,12)-(172,15) = "end" + ├── @ DefNode (location: (174,0)-(174,15)) + │ ├── name: :f + │ ├── name_loc: (174,4)-(174,5) = "f" + │ ├── receiver: ∅ + │ ├── parameters: + │ │ @ ParametersNode (location: (174,6)-(174,10)) + │ │ ├── requireds: (length: 0) + │ │ ├── optionals: (length: 0) + │ │ ├── rest: ∅ + │ │ ├── posts: (length: 0) + │ │ ├── keywords: (length: 1) + │ │ │ └── @ OptionalKeywordParameterNode (location: (174,6)-(174,10)) + │ │ │ ├── name: :x + │ │ │ ├── name_loc: (174,6)-(174,8) = "x:" + │ │ │ └── value: + │ │ │ @ CallNode (location: (174,8)-(174,10)) + │ │ │ ├── receiver: + │ │ │ │ @ CallNode (location: (174,9)-(174,10)) + │ │ │ │ ├── receiver: ∅ + │ │ │ │ ├── call_operator_loc: ∅ + │ │ │ │ ├── message_loc: (174,9)-(174,10) = "a" + │ │ │ │ ├── opening_loc: ∅ + │ │ │ │ ├── arguments: ∅ + │ │ │ │ ├── closing_loc: ∅ + │ │ │ │ ├── block: ∅ + │ │ │ │ ├── flags: variable_call + │ │ │ │ └── name: :a + │ │ │ ├── call_operator_loc: ∅ + │ │ │ ├── message_loc: (174,8)-(174,9) = "+" + │ │ │ ├── opening_loc: ∅ + │ │ │ ├── arguments: ∅ + │ │ │ ├── closing_loc: ∅ + │ │ │ ├── block: ∅ + │ │ │ ├── flags: ∅ + │ │ │ └── name: :+@ + │ │ ├── keyword_rest: ∅ + │ │ └── block: ∅ + │ ├── body: ∅ + │ ├── locals: [:x] + │ ├── def_keyword_loc: (174,0)-(174,3) = "def" + │ ├── operator_loc: ∅ + │ ├── lparen_loc: ∅ + │ ├── rparen_loc: ∅ + │ ├── equal_loc: ∅ + │ └── end_keyword_loc: (174,12)-(174,15) = "end" + ├── @ DefNode (location: (176,0)-(176,15)) + │ ├── name: :f + │ ├── name_loc: (176,4)-(176,5) = "f" + │ ├── receiver: ∅ + │ ├── parameters: + │ │ @ ParametersNode (location: (176,6)-(176,10)) + │ │ ├── requireds: (length: 0) + │ │ ├── optionals: (length: 0) + │ │ ├── rest: ∅ + │ │ ├── posts: (length: 0) + │ │ ├── keywords: (length: 1) + │ │ │ └── @ OptionalKeywordParameterNode (location: (176,6)-(176,10)) + │ │ │ ├── name: :x + │ │ │ ├── name_loc: (176,6)-(176,8) = "x:" + │ │ │ └── value: + │ │ │ @ CallNode (location: (176,8)-(176,10)) + │ │ │ ├── receiver: + │ │ │ │ @ CallNode (location: (176,9)-(176,10)) + │ │ │ │ ├── receiver: ∅ + │ │ │ │ ├── call_operator_loc: ∅ + │ │ │ │ ├── message_loc: (176,9)-(176,10) = "a" + │ │ │ │ ├── opening_loc: ∅ + │ │ │ │ ├── arguments: ∅ + │ │ │ │ ├── closing_loc: ∅ + │ │ │ │ ├── block: ∅ + │ │ │ │ ├── flags: variable_call + │ │ │ │ └── name: :a + │ │ │ ├── call_operator_loc: ∅ + │ │ │ ├── message_loc: (176,8)-(176,9) = "!" + │ │ │ ├── opening_loc: ∅ + │ │ │ ├── arguments: ∅ + │ │ │ ├── closing_loc: ∅ + │ │ │ ├── block: ∅ + │ │ │ ├── flags: ∅ + │ │ │ └── name: :! + │ │ ├── keyword_rest: ∅ + │ │ └── block: ∅ + │ ├── body: ∅ + │ ├── locals: [:x] + │ ├── def_keyword_loc: (176,0)-(176,3) = "def" + │ ├── operator_loc: ∅ + │ ├── lparen_loc: ∅ + │ ├── rparen_loc: ∅ + │ ├── equal_loc: ∅ + │ └── end_keyword_loc: (176,12)-(176,15) = "end" + └── @ DefNode (location: (178,0)-(178,20)) + ├── name: :foo + ├── name_loc: (178,4)-(178,7) = "foo" ├── receiver: ∅ ├── parameters: - │ @ ParametersNode (location: (170,6)-(170,7)) + │ @ ParametersNode (location: (178,8)-(178,15)) │ ├── requireds: (length: 0) │ ├── optionals: (length: 0) - │ ├── rest: - │ │ @ RestParameterNode (location: (170,6)-(170,7)) - │ │ ├── name: ∅ - │ │ ├── name_loc: ∅ - │ │ └── operator_loc: (170,6)-(170,7) = "*" + │ ├── rest: ∅ │ ├── posts: (length: 0) - │ ├── keywords: (length: 0) + │ ├── keywords: (length: 1) + │ │ └── @ OptionalKeywordParameterNode (location: (178,8)-(178,15)) + │ │ ├── name: :x + │ │ ├── name_loc: (178,8)-(178,10) = "x:" + │ │ └── value: + │ │ @ StringNode (location: (178,10)-(178,15)) + │ │ ├── flags: ∅ + │ │ ├── opening_loc: (178,10)-(178,12) = "%(" + │ │ ├── content_loc: (178,12)-(178,14) = "xx" + │ │ ├── closing_loc: (178,14)-(178,15) = ")" + │ │ └── unescaped: "xx" │ ├── keyword_rest: ∅ │ └── block: ∅ - ├── body: - │ @ StatementsNode (location: (170,10)-(170,13)) - │ └── body: (length: 1) - │ └── @ ArrayNode (location: (170,10)-(170,13)) - │ ├── elements: (length: 1) - │ │ └── @ SplatNode (location: (170,11)-(170,12)) - │ │ ├── operator_loc: (170,11)-(170,12) = "*" - │ │ └── expression: ∅ - │ ├── opening_loc: (170,10)-(170,11) = "[" - │ └── closing_loc: (170,12)-(170,13) = "]" - ├── locals: [:*] - ├── def_keyword_loc: (170,0)-(170,3) = "def" + ├── body: ∅ + ├── locals: [:x] + ├── def_keyword_loc: (178,0)-(178,3) = "def" ├── operator_loc: ∅ - ├── lparen_loc: (170,5)-(170,6) = "(" - ├── rparen_loc: (170,7)-(170,8) = ")" + ├── lparen_loc: ∅ + ├── rparen_loc: ∅ ├── equal_loc: ∅ - └── end_keyword_loc: (170,15)-(170,18) = "end" + └── end_keyword_loc: (178,17)-(178,20) = "end" |
