diff options
author | Kevin Newton <kddnewton@gmail.com> | 2024-01-24 14:24:13 -0500 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2024-01-24 15:02:32 -0500 |
commit | 44c337a397b1159c7bc843a501d6a0a51e65430f (patch) | |
tree | c3fe940c105fdacbafd4e6398a4152bbd05fafc0 | |
parent | c888b8d63b714d5ccf107272b10d723c75fbe7dd (diff) | |
download | ruby-44c337a397b1159c7bc843a501d6a0a51e65430f.tar.gz |
[PRISM] Support __LINE__, __FILE__, and __ENCODING__ in patterns, fix pinned expressions
-rw-r--r-- | prism_compile.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/prism_compile.c b/prism_compile.c index 20eb457bfb..b88d90bae0 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -2078,6 +2078,13 @@ pm_compile_pattern(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_node_t CHECK(pm_compile_pattern(iseq, scope_node, cast->right, ret, src, matched_label, unmatched_label, in_single_pattern, true, true, base_index)); break; } + case PM_PINNED_EXPRESSION_NODE: + // Pinned expressions are a way to match against the value of an + // expression that should be evaluated at runtime. This looks like: + // foo in ^(bar). To compile these, we compile the expression as if it + // were a literal value by falling through to the literal case. + node = ((pm_pinned_expression_node_t *) node)->expression; + /* fallthrough */ case PM_ARRAY_NODE: case PM_CLASS_VARIABLE_READ_NODE: case PM_CONSTANT_PATH_NODE: @@ -2095,6 +2102,9 @@ pm_compile_pattern(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_node_t case PM_LAMBDA_NODE: case PM_LOCAL_VARIABLE_READ_NODE: case PM_NIL_NODE: + case PM_SOURCE_ENCODING_NODE: + case PM_SOURCE_FILE_NODE: + case PM_SOURCE_LINE_NODE: case PM_RANGE_NODE: case PM_RATIONAL_NODE: case PM_REGULAR_EXPRESSION_NODE: @@ -2130,15 +2140,6 @@ pm_compile_pattern(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_node_t CHECK(pm_compile_pattern(iseq, scope_node, cast->variable, ret, src, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern, true, base_index)); break; } - case PM_PINNED_EXPRESSION_NODE: { - // Pinned expressions are a way to match against the value of an - // expression that should be evaluated at runtime. This looks like: - // foo in ^(bar). To compile these, we compile the expression that they - // hold. - pm_pinned_expression_node_t *cast = (pm_pinned_expression_node_t *) node; - CHECK(pm_compile_pattern(iseq, scope_node, cast->expression, ret, src, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern, true, base_index)); - break; - } case PM_IF_NODE: case PM_UNLESS_NODE: { // If and unless nodes can show up here as guards on `in` clauses. This |