diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-11-30 19:04:29 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-11-30 21:40:22 +0900 |
commit | 1802d14ca8924bd67e0915c5ad9f1fad5dba0602 (patch) | |
tree | 8fd0c1c99598196b4e9416d522688c8558bcdd7a /parse.y | |
parent | 0cdad3b92a7e117bc7e36779140f5c83b07ca7ce (diff) | |
download | ruby-1802d14ca8924bd67e0915c5ad9f1fad5dba0602.tar.gz |
[Bug #19877] Assign captures for direct regexp literal only
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -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: |