[ruby/prism] Fix binding power for modifier rescue

https://github.com/ruby/prism/commit/f614863d79
This commit is contained in:
Kevin Newton 2024-01-29 13:37:22 -05:00 коммит произвёл git
Родитель 1005b7d29f
Коммит d39d9e066f
3 изменённых файлов: 115 добавлений и 70 удалений

Просмотреть файл

@ -10385,8 +10385,8 @@ parser_lex(pm_parser_t *parser) {
typedef enum {
PM_BINDING_POWER_UNSET = 0, // used to indicate this token cannot be used as an infix operator
PM_BINDING_POWER_STATEMENT = 2,
PM_BINDING_POWER_MODIFIER = 4, // if unless until while
PM_BINDING_POWER_MODIFIER_RESCUE = 6, // rescue
PM_BINDING_POWER_MODIFIER_RESCUE = 4, // rescue
PM_BINDING_POWER_MODIFIER = 6, // if unless until while
PM_BINDING_POWER_COMPOSITION = 8, // and or
PM_BINDING_POWER_NOT = 10, // not
PM_BINDING_POWER_MATCH = 12, // => in
@ -10440,15 +10440,15 @@ typedef struct {
#define RIGHT_ASSOCIATIVE_UNARY(precedence) { precedence, precedence, false, false }
pm_binding_powers_t pm_binding_powers[PM_TOKEN_MAXIMUM] = {
// rescue
[PM_TOKEN_KEYWORD_RESCUE_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER_RESCUE),
// if unless until while
[PM_TOKEN_KEYWORD_IF_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER),
[PM_TOKEN_KEYWORD_UNLESS_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER),
[PM_TOKEN_KEYWORD_UNTIL_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER),
[PM_TOKEN_KEYWORD_WHILE_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER),
// rescue
[PM_TOKEN_KEYWORD_RESCUE_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER_RESCUE),
// and or
[PM_TOKEN_KEYWORD_AND] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_COMPOSITION),
[PM_TOKEN_KEYWORD_OR] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_COMPOSITION),
@ -17472,7 +17472,7 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
case PM_UNDEF_NODE:
// These expressions are statements, and cannot be followed by
// operators (except modifiers).
if (pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER_RESCUE) {
if (pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER) {
return node;
}
break;

Просмотреть файл

@ -29,3 +29,5 @@ def a
a b:
rescue
end
foo if bar rescue baz

Просмотреть файл

@ -1,8 +1,8 @@
@ ProgramNode (location: (1,0)-(31,3))
@ ProgramNode (location: (1,0)-(33,21))
├── locals: [:a]
└── statements:
@ StatementsNode (location: (1,0)-(31,3))
└── body: (length: 12)
@ StatementsNode (location: (1,0)-(33,21))
└── body: (length: 13)
├── @ RescueModifierNode (location: (1,0)-(1,14))
│ ├── expression:
│ │ @ CallNode (location: (1,0)-(1,3))
@ -321,71 +321,114 @@
│ ├── rparen_loc: ∅
│ ├── equal_loc: (26,16)-(26,17) = "="
│ └── end_keyword_loc: ∅
└── @ DefNode (location: (28,0)-(31,3))
├── name: :a
├── name_loc: (28,4)-(28,5) = "a"
├── receiver: ∅
├── parameters: ∅
├── body:
│ @ BeginNode (location: (29,2)-(31,3))
│ ├── begin_keyword_loc: ∅
├── @ DefNode (location: (28,0)-(31,3))
│ ├── name: :a
│ ├── name_loc: (28,4)-(28,5) = "a"
│ ├── receiver: ∅
│ ├── parameters: ∅
│ ├── body:
│ │ @ BeginNode (location: (29,2)-(31,3))
│ │ ├── begin_keyword_loc: ∅
│ │ ├── statements:
│ │ │ @ StatementsNode (location: (29,2)-(29,6))
│ │ │ └── body: (length: 1)
│ │ │ └── @ CallNode (location: (29,2)-(29,6))
│ │ │ ├── flags: ignore_visibility
│ │ │ ├── receiver: ∅
│ │ │ ├── call_operator_loc: ∅
│ │ │ ├── name: :a
│ │ │ ├── message_loc: (29,2)-(29,3) = "a"
│ │ │ ├── opening_loc: ∅
│ │ │ ├── arguments:
│ │ │ │ @ ArgumentsNode (location: (29,4)-(29,6))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── arguments: (length: 1)
│ │ │ │ └── @ KeywordHashNode (location: (29,4)-(29,6))
│ │ │ │ ├── flags: symbol_keys
│ │ │ │ └── elements: (length: 1)
│ │ │ │ └── @ AssocNode (location: (29,4)-(29,6))
│ │ │ │ ├── key:
│ │ │ │ │ @ SymbolNode (location: (29,4)-(29,6))
│ │ │ │ │ ├── flags: forced_us_ascii_encoding
│ │ │ │ │ ├── opening_loc: ∅
│ │ │ │ │ ├── value_loc: (29,4)-(29,5) = "b"
│ │ │ │ │ ├── closing_loc: (29,5)-(29,6) = ":"
│ │ │ │ │ └── unescaped: "b"
│ │ │ │ ├── value:
│ │ │ │ │ @ ImplicitNode (location: (29,4)-(29,6))
│ │ │ │ │ └── value:
│ │ │ │ │ @ CallNode (location: (29,4)-(29,6))
│ │ │ │ │ ├── flags: ignore_visibility
│ │ │ │ │ ├── receiver: ∅
│ │ │ │ │ ├── call_operator_loc: ∅
│ │ │ │ │ ├── name: :b
│ │ │ │ │ ├── message_loc: (29,4)-(29,5) = "b"
│ │ │ │ │ ├── opening_loc: ∅
│ │ │ │ │ ├── arguments: ∅
│ │ │ │ │ ├── closing_loc: ∅
│ │ │ │ │ └── block: ∅
│ │ │ │ └── operator_loc: ∅
│ │ │ ├── closing_loc: ∅
│ │ │ └── block: ∅
│ │ ├── rescue_clause:
│ │ │ @ RescueNode (location: (30,0)-(30,6))
│ │ │ ├── keyword_loc: (30,0)-(30,6) = "rescue"
│ │ │ ├── exceptions: (length: 0)
│ │ │ ├── operator_loc: ∅
│ │ │ ├── reference: ∅
│ │ │ ├── statements: ∅
│ │ │ └── consequent: ∅
│ │ ├── else_clause: ∅
│ │ ├── ensure_clause: ∅
│ │ └── end_keyword_loc: (31,0)-(31,3) = "end"
│ ├── locals: []
│ ├── locals_body_index: 0
│ ├── def_keyword_loc: (28,0)-(28,3) = "def"
│ ├── operator_loc: ∅
│ ├── lparen_loc: ∅
│ ├── rparen_loc: ∅
│ ├── equal_loc: ∅
│ └── end_keyword_loc: (31,0)-(31,3) = "end"
└── @ RescueModifierNode (location: (33,0)-(33,21))
├── expression:
│ @ IfNode (location: (33,0)-(33,10))
│ ├── if_keyword_loc: (33,4)-(33,6) = "if"
│ ├── predicate:
│ │ @ CallNode (location: (33,7)-(33,10))
│ │ ├── flags: variable_call, ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :bar
│ │ ├── message_loc: (33,7)-(33,10) = "bar"
│ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ └── block: ∅
│ ├── then_keyword_loc: ∅
│ ├── statements:
│ │ @ StatementsNode (location: (29,2)-(29,6))
│ │ @ StatementsNode (location: (33,0)-(33,3))
│ │ └── body: (length: 1)
│ │ └── @ CallNode (location: (29,2)-(29,6))
│ │ ├── flags: ignore_visibility
│ │ └── @ CallNode (location: (33,0)-(33,3))
│ │ ├── flags: variable_call, ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :a
│ │ ├── message_loc: (29,2)-(29,3) = "a"
│ │ ├── name: :foo
│ │ ├── message_loc: (33,0)-(33,3) = "foo"
│ │ ├── opening_loc: ∅
│ │ ├── arguments:
│ │ │ @ ArgumentsNode (location: (29,4)-(29,6))
│ │ │ ├── flags: ∅
│ │ │ └── arguments: (length: 1)
│ │ │ └── @ KeywordHashNode (location: (29,4)-(29,6))
│ │ │ ├── flags: symbol_keys
│ │ │ └── elements: (length: 1)
│ │ │ └── @ AssocNode (location: (29,4)-(29,6))
│ │ │ ├── key:
│ │ │ │ @ SymbolNode (location: (29,4)-(29,6))
│ │ │ │ ├── flags: forced_us_ascii_encoding
│ │ │ │ ├── opening_loc: ∅
│ │ │ │ ├── value_loc: (29,4)-(29,5) = "b"
│ │ │ │ ├── closing_loc: (29,5)-(29,6) = ":"
│ │ │ │ └── unescaped: "b"
│ │ │ ├── value:
│ │ │ │ @ ImplicitNode (location: (29,4)-(29,6))
│ │ │ │ └── value:
│ │ │ │ @ CallNode (location: (29,4)-(29,6))
│ │ │ │ ├── flags: ignore_visibility
│ │ │ │ ├── receiver: ∅
│ │ │ │ ├── call_operator_loc: ∅
│ │ │ │ ├── name: :b
│ │ │ │ ├── message_loc: (29,4)-(29,5) = "b"
│ │ │ │ ├── opening_loc: ∅
│ │ │ │ ├── arguments: ∅
│ │ │ │ ├── closing_loc: ∅
│ │ │ │ └── block: ∅
│ │ │ └── operator_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ └── block: ∅
│ ├── rescue_clause:
│ │ @ RescueNode (location: (30,0)-(30,6))
│ │ ├── keyword_loc: (30,0)-(30,6) = "rescue"
│ │ ├── exceptions: (length: 0)
│ │ ├── operator_loc: ∅
│ │ ├── reference: ∅
│ │ ├── statements: ∅
│ │ └── consequent: ∅
│ ├── else_clause: ∅
│ ├── ensure_clause: ∅
│ └── end_keyword_loc: (31,0)-(31,3) = "end"
├── locals: []
├── locals_body_index: 0
├── def_keyword_loc: (28,0)-(28,3) = "def"
├── operator_loc: ∅
├── lparen_loc: ∅
├── rparen_loc: ∅
├── equal_loc: ∅
└── end_keyword_loc: (31,0)-(31,3) = "end"
│ ├── consequent: ∅
│ └── end_keyword_loc: ∅
├── keyword_loc: (33,11)-(33,17) = "rescue"
└── rescue_expression:
@ CallNode (location: (33,18)-(33,21))
├── flags: variable_call, ignore_visibility
├── receiver: ∅
├── call_operator_loc: ∅
├── name: :baz
├── message_loc: (33,18)-(33,21) = "baz"
├── opening_loc: ∅
├── arguments: ∅
├── closing_loc: ∅
└── block: ∅