aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-11-30 19:04:29 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-11-30 21:40:22 +0900
commit1802d14ca8924bd67e0915c5ad9f1fad5dba0602 (patch)
tree8fd0c1c99598196b4e9416d522688c8558bcdd7a /parse.y
parent0cdad3b92a7e117bc7e36779140f5c83b07ca7ce (diff)
downloadruby-1802d14ca8924bd67e0915c5ad9f1fad5dba0602.tar.gz
[Bug #19877] Assign captures for direct regexp literal only
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y20
1 files changed, 15 insertions, 5 deletions
diff --git a/parse.y b/parse.y
index 94eb6f3e5a..865d26c0f3 100644
--- a/parse.y
+++ b/parse.y
@@ -1149,8 +1149,16 @@ set_embraced_location(NODE *node, const rb_code_location_t *beg, const rb_code_l
static NODE *
last_expr_node(NODE *expr)
{
- if (nd_type_p(expr, NODE_BLOCK)) {
- expr = RNODE_BLOCK(RNODE_BLOCK(expr)->nd_end)->nd_head;
+ while (expr) {
+ if (nd_type_p(expr, NODE_BLOCK)) {
+ expr = RNODE_BLOCK(RNODE_BLOCK(expr)->nd_end)->nd_head;
+ }
+ else if (nd_type_p(expr, NODE_BEGIN)) {
+ expr = RNODE_BEGIN(expr)->nd_body;
+ }
+ else {
+ break;
+ }
}
return expr;
}
@@ -3887,7 +3895,7 @@ primary : literal
{
/*%%%*/
if (nd_type_p($2, NODE_SELF)) RNODE_SELF($2)->nd_state = 0;
- $$ = $2;
+ $$ = NEW_BEGIN($2, &@$);
/*% %*/
/*% ripper: paren!($2) %*/
}
@@ -12600,8 +12608,6 @@ static NODE*
last_expr_once_body(NODE *node)
{
if (!node) return 0;
- node = last_expr_node(node);
- if (!node) return 0;
return nd_once_body(node);
}
@@ -14096,6 +14102,10 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l
assign_in_cond(p, node);
switch (nd_type(node)) {
+ case NODE_BEGIN:
+ RNODE_BEGIN(node)->nd_body = cond0(p, RNODE_BEGIN(node)->nd_body, type, loc);
+ break;
+
case NODE_DSTR:
case NODE_EVSTR:
case NODE_STR: