[ruby/prism] Fix parsing rescue modifier

https://github.com/ruby/prism/commit/b7407ae3c0
This commit is contained in:
Haldun Bayhantopcu 2024-02-15 16:30:58 +01:00 коммит произвёл git
Родитель a7718c914a
Коммит a021702596
3 изменённых файлов: 112 добавлений и 43 удалений

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

@ -16769,7 +16769,18 @@ parse_assignment_values(pm_parser_t *parser, pm_binding_power_t previous_binding
if (is_single_value && match1(parser, PM_TOKEN_KEYWORD_RESCUE_MODIFIER)) { if (is_single_value && match1(parser, PM_TOKEN_KEYWORD_RESCUE_MODIFIER)) {
pm_token_t rescue = parser->current; pm_token_t rescue = parser->current;
parser_lex(parser); parser_lex(parser);
pm_node_t *right = parse_expression(parser, binding_power, false, PM_ERR_RESCUE_MODIFIER_VALUE);
bool accepts_command_call_inner = false;
// RHS can accept command call iff the value is a call with arguments but without paranthesis.
if (PM_NODE_TYPE_P(value, PM_CALL_NODE)) {
pm_call_node_t *call_node = (pm_call_node_t *)value;
if ((call_node->arguments != NULL) && (call_node->opening_loc.start == NULL)) {
accepts_command_call_inner = true;
}
}
pm_node_t *right = parse_expression(parser, binding_power, accepts_command_call_inner, PM_ERR_RESCUE_MODIFIER_VALUE);
return (pm_node_t *) pm_rescue_modifier_node_create(parser, value, &rescue, right); return (pm_node_t *) pm_rescue_modifier_node_create(parser, value, &rescue, right);
} }

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

@ -31,3 +31,5 @@ rescue
end end
foo if bar rescue baz foo if bar rescue baz
z = x y rescue c d

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

@ -1,8 +1,8 @@
@ ProgramNode (location: (1,0)-(33,21)) @ ProgramNode (location: (1,0)-(35,18))
├── locals: [:a] ├── locals: [:a, :z]
└── statements: └── statements:
@ StatementsNode (location: (1,0)-(33,21)) @ StatementsNode (location: (1,0)-(35,18))
└── body: (length: 13) └── body: (length: 14)
├── @ RescueModifierNode (location: (1,0)-(1,14)) ├── @ RescueModifierNode (location: (1,0)-(1,14))
│ ├── expression: │ ├── expression:
│ │ @ CallNode (location: (1,0)-(1,3)) │ │ @ CallNode (location: (1,0)-(1,3))
@ -386,46 +386,102 @@
│ ├── rparen_loc: ∅ │ ├── rparen_loc: ∅
│ ├── equal_loc: ∅ │ ├── equal_loc: ∅
│ └── end_keyword_loc: (31,0)-(31,3) = "end" │ └── end_keyword_loc: (31,0)-(31,3) = "end"
└── @ RescueModifierNode (location: (33,0)-(33,21)) ├── @ RescueModifierNode (location: (33,0)-(33,21))
├── expression: │ ├── expression:
│ @ IfNode (location: (33,0)-(33,10)) │ │ @ IfNode (location: (33,0)-(33,10))
│ ├── if_keyword_loc: (33,4)-(33,6) = "if" │ │ ├── if_keyword_loc: (33,4)-(33,6) = "if"
│ ├── predicate: │ │ ├── predicate:
│ │ @ CallNode (location: (33,7)-(33,10)) │ │ │ @ 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: (33,0)-(33,3))
│ │ │ └── body: (length: 1)
│ │ │ └── @ CallNode (location: (33,0)-(33,3))
│ │ │ ├── flags: variable_call, ignore_visibility
│ │ │ ├── receiver: ∅
│ │ │ ├── call_operator_loc: ∅
│ │ │ ├── name: :foo
│ │ │ ├── message_loc: (33,0)-(33,3) = "foo"
│ │ │ ├── opening_loc: ∅
│ │ │ ├── arguments: ∅
│ │ │ ├── closing_loc: ∅
│ │ │ └── block: ∅
│ │ ├── 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: ∅
└── @ LocalVariableWriteNode (location: (35,0)-(35,18))
├── name: :z
├── depth: 0
├── name_loc: (35,0)-(35,1) = "z"
├── value:
│ @ RescueModifierNode (location: (35,4)-(35,18))
│ ├── expression:
│ │ @ CallNode (location: (35,4)-(35,7))
│ │ ├── flags: ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :x
│ │ ├── message_loc: (35,4)-(35,5) = "x"
│ │ ├── opening_loc: ∅
│ │ ├── arguments:
│ │ │ @ ArgumentsNode (location: (35,6)-(35,7))
│ │ │ ├── flags: ∅
│ │ │ └── arguments: (length: 1)
│ │ │ └── @ CallNode (location: (35,6)-(35,7))
│ │ │ ├── flags: variable_call, ignore_visibility
│ │ │ ├── receiver: ∅
│ │ │ ├── call_operator_loc: ∅
│ │ │ ├── name: :y
│ │ │ ├── message_loc: (35,6)-(35,7) = "y"
│ │ │ ├── opening_loc: ∅
│ │ │ ├── arguments: ∅
│ │ │ ├── closing_loc: ∅
│ │ │ └── block: ∅
│ │ ├── closing_loc: ∅
│ │ └── block: ∅
│ ├── keyword_loc: (35,8)-(35,14) = "rescue"
│ └── rescue_expression:
│ @ CallNode (location: (35,15)-(35,18))
│ ├── flags: ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :c
│ ├── message_loc: (35,15)-(35,16) = "c"
│ ├── opening_loc: ∅
│ ├── arguments:
│ │ @ ArgumentsNode (location: (35,17)-(35,18))
│ │ ├── flags: ∅
│ │ └── arguments: (length: 1)
│ │ └── @ CallNode (location: (35,17)-(35,18))
│ │ ├── flags: variable_call, ignore_visibility │ │ ├── flags: variable_call, ignore_visibility
│ │ ├── receiver: ∅ │ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅ │ │ ├── call_operator_loc: ∅
│ │ ├── name: :bar │ ├── name: :d
│ │ ├── message_loc: (33,7)-(33,10) = "bar" │ ├── message_loc: (35,17)-(35,18) = "d"
│ │ ├── opening_loc: ∅ │ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅ │ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅ │ │ ├── closing_loc: ∅
│ │ └── block: ∅ │ │ └── block: ∅
│ ├── then_keyword_loc: ∅ │ ├── closing_loc: ∅
│ ├── statements: │ └── block: ∅
│ │ @ StatementsNode (location: (33,0)-(33,3)) └── operator_loc: (35,2)-(35,3) = "="
│ │ └── body: (length: 1)
│ │ └── @ CallNode (location: (33,0)-(33,3))
│ │ ├── flags: variable_call, ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :foo
│ │ ├── message_loc: (33,0)-(33,3) = "foo"
│ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ └── block: ∅
│ ├── 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: ∅