[ruby/prism] Join range checks into the main parse_expression switch

https://github.com/ruby/prism/commit/ed4523464b
This commit is contained in:
Kevin Newton 2023-11-22 09:37:38 -05:00 committed by git
parent 8794836bf2
commit 8f707e8030

View File

@ -16768,7 +16768,6 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
static pm_node_t *
parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, pm_diagnostic_id_t diag_id) {
pm_token_t recovery = parser->previous;
bool is_udot = parser->current.type == PM_TOKEN_UDOT_DOT || parser->current.type == PM_TOKEN_UDOT_DOT_DOT;
pm_node_t *node = parse_expression_prefix(parser, binding_power);
switch (PM_NODE_TYPE(node)) {
@ -16788,18 +16787,20 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, pm_diagn
if (pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER_RESCUE) {
return node;
}
break;
case PM_RANGE_NODE:
// Range operators are non-associative, so that it does not
// associate with other range operators (i.e. `..1..` should be
// rejected.) For this reason, we check such a case for unary ranges
// here, and if so, it returns the node immediately,
if ((((pm_range_node_t *) node)->left == NULL) && pm_binding_powers[parser->current.type].left >= PM_BINDING_POWER_RANGE) {
return node;
}
break;
default:
break;
}
// Range operators are non-associative, so that it does not associate with
// other range operators (i.e. `..1..` should be rejected.)
// For this reason, we check such a case for unary ranges here, and if so,
// it returns the node immediately,
if (is_udot && pm_binding_powers[parser->current.type].left >= PM_BINDING_POWER_RANGE) {
return node;
}
// Otherwise we'll look and see if the next token can be parsed as an infix
// operator. If it can, then we'll parse it using parse_expression_infix.
pm_binding_powers_t current_binding_powers;