aboutsummaryrefslogtreecommitdiffstats
path: root/prism
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-11-22 09:32:45 -0500
committergit <svn-admin@ruby-lang.org>2023-11-22 14:53:28 +0000
commit2aefbbaab9c9a86fb70f30bca86ed73411679d6d (patch)
treee61a02fad92a1141c8cad5f7c9202de8bfe9fccf /prism
parentcdd07781b00b41b4f1f25fe9b12cd43d60a92834 (diff)
downloadruby-2aefbbaab9c9a86fb70f30bca86ed73411679d6d.tar.gz
[ruby/prism] Combine expression checks into a single switch
https://github.com/ruby/prism/commit/825d5d7bd4
Diffstat (limited to 'prism')
-rw-r--r--prism/prism.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 56b565a38d..db9c1ad7e1 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -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_node_t *node = parse_expression_prefix(parser, binding_power);
- // If we found a syntax error, then the type of node returned by
- // parse_expression_prefix is going to be a missing node. In that case we need
- // to add the error message to the parser's error list.
- if (PM_NODE_TYPE_P(node, PM_MISSING_NODE)) {
- pm_parser_err(parser, recovery.end, recovery.end, diag_id);
- return node;
- }
-
- // The statements BEGIN { ... }, END { ... }, alias ..., and undef ... are statement.
- // They cannot follow operators, but they can follow modifiers.
- bool is_statement =
- PM_NODE_TYPE_P(node, PM_PRE_EXECUTION_NODE) || PM_NODE_TYPE_P(node, PM_POST_EXECUTION_NODE) ||
- PM_NODE_TYPE_P(node, PM_ALIAS_GLOBAL_VARIABLE_NODE) || PM_NODE_TYPE_P(node, PM_ALIAS_METHOD_NODE) ||
- PM_NODE_TYPE_P(node, PM_UNDEF_NODE);
- if (is_statement && pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER_RESCUE) {
- return node;
+ switch (PM_NODE_TYPE(node)) {
+ case PM_MISSING_NODE:
+ // If we found a syntax error, then the type of node returned by
+ // parse_expression_prefix is going to be a missing node. In that
+ // case we need to add the error message to the parser's error list.
+ pm_parser_err(parser, recovery.end, recovery.end, diag_id);
+ return node;
+ case PM_PRE_EXECUTION_NODE:
+ case PM_POST_EXECUTION_NODE:
+ case PM_ALIAS_GLOBAL_VARIABLE_NODE:
+ case PM_ALIAS_METHOD_NODE:
+ 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) {
+ return node;
+ }
+ default:
+ break;
}
// Otherwise we'll look and see if the next token can be parsed as an infix