[ruby/prism] Combine expression checks into a single switch
https://github.com/ruby/prism/commit/825d5d7bd4
This commit is contained in:
parent
cdd07781b0
commit
2aefbbaab9
@ -16768,22 +16768,25 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, pm_diagn
|
|||||||
pm_token_t recovery = parser->previous;
|
pm_token_t recovery = parser->previous;
|
||||||
pm_node_t *node = parse_expression_prefix(parser, binding_power);
|
pm_node_t *node = parse_expression_prefix(parser, binding_power);
|
||||||
|
|
||||||
// If we found a syntax error, then the type of node returned by
|
switch (PM_NODE_TYPE(node)) {
|
||||||
// parse_expression_prefix is going to be a missing node. In that case we need
|
case PM_MISSING_NODE:
|
||||||
// to add the error message to the parser's error list.
|
// If we found a syntax error, then the type of node returned by
|
||||||
if (PM_NODE_TYPE_P(node, PM_MISSING_NODE)) {
|
// parse_expression_prefix is going to be a missing node. In that
|
||||||
pm_parser_err(parser, recovery.end, recovery.end, diag_id);
|
// case we need to add the error message to the parser's error list.
|
||||||
return node;
|
pm_parser_err(parser, recovery.end, recovery.end, diag_id);
|
||||||
}
|
return node;
|
||||||
|
case PM_PRE_EXECUTION_NODE:
|
||||||
// The statements BEGIN { ... }, END { ... }, alias ..., and undef ... are statement.
|
case PM_POST_EXECUTION_NODE:
|
||||||
// They cannot follow operators, but they can follow modifiers.
|
case PM_ALIAS_GLOBAL_VARIABLE_NODE:
|
||||||
bool is_statement =
|
case PM_ALIAS_METHOD_NODE:
|
||||||
PM_NODE_TYPE_P(node, PM_PRE_EXECUTION_NODE) || PM_NODE_TYPE_P(node, PM_POST_EXECUTION_NODE) ||
|
case PM_UNDEF_NODE:
|
||||||
PM_NODE_TYPE_P(node, PM_ALIAS_GLOBAL_VARIABLE_NODE) || PM_NODE_TYPE_P(node, PM_ALIAS_METHOD_NODE) ||
|
// These expressions are statements, and cannot be followed by
|
||||||
PM_NODE_TYPE_P(node, PM_UNDEF_NODE);
|
// operators (except modifiers).
|
||||||
if (is_statement && pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER_RESCUE) {
|
if (pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER_RESCUE) {
|
||||||
return node;
|
return node;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise we'll look and see if the next token can be parsed as an infix
|
// Otherwise we'll look and see if the next token can be parsed as an infix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user