@@ -503,6 +503,8 @@ static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VAL
503
503
504
504
#define new_op_assign (lhs, op, rhs ) new_op_assign_gen(parser, (lhs), (op), (rhs))
505
505
506
+ RUBY_FUNC_EXPORTED VALUE rb_parser_reg_compile (struct parser_params * parser, VALUE str, int options, VALUE *errmsg);
507
+
506
508
static ID formal_argument_gen (struct parser_params *, ID);
507
509
#define formal_argument (id ) formal_argument_gen(parser, (id))
508
510
static ID shadowing_lvar_gen (struct parser_params *,ID);
@@ -3991,6 +3993,19 @@ regexp : tREGEXP_BEG regexp_contents tREGEXP_END
3991
3993
}
3992
3994
$$ = node;
3993
3995
/* %
3996
+ VALUE re = $2, opt = $3, src = 0, err;
3997
+ int options = 0;
3998
+ if (ripper_is_node_yylval(re)) {
3999
+ $2 = RNODE(re)->nd_rval;
4000
+ src = RNODE(re)->nd_cval;
4001
+ }
4002
+ if (ripper_is_node_yylval(opt)) {
4003
+ $3 = RNODE(opt)->nd_rval;
4004
+ options = (int)RNODE(opt)->nd_state;
4005
+ }
4006
+ if (src && NIL_P(rb_parser_reg_compile(parser, src, options, &err))) {
4007
+ compile_error(PARSER_ARG "%"PRIsVALUE, err);
4008
+ }
3994
4009
$$ = dispatch2(regexp_literal, $2, $3);
3995
4010
%*/
3996
4011
}
@@ -4215,7 +4230,7 @@ regexp_contents: /* none */
4215
4230
/* %%%*/
4216
4231
$$ = 0 ;
4217
4232
/* %
4218
- $$ = dispatch0(regexp_new);
4233
+ $$ = ripper_new_yylval(0, dispatch0(regexp_new), 0 );
4219
4234
%*/
4220
4235
}
4221
4236
| regexp_contents string_content
@@ -4242,7 +4257,20 @@ regexp_contents: /* none */
4242
4257
$$ = list_append(head, tail);
4243
4258
}
4244
4259
/* %
4245
- $$ = dispatch2(regexp_add, $1, $2);
4260
+ VALUE s1 = 0, s2 = 0, n1 = $1, n2 = $2;
4261
+ if (ripper_is_node_yylval(n1)) {
4262
+ s1 = RNODE(n2)->nd_cval;
4263
+ n1 = RNODE(n1)->nd_rval;
4264
+ }
4265
+ if (ripper_is_node_yylval(n2)) {
4266
+ s2 = RNODE(n2)->nd_cval;
4267
+ n2 = RNODE(n2)->nd_rval;
4268
+ }
4269
+ $$ = dispatch2(regexp_add, n1, n2);
4270
+ if (s1 || s2) {
4271
+ VALUE s = !s1 ? s2 : !s2 ? s1 : rb_str_plus(s1, s2);
4272
+ $$ = ripper_new_yylval(0, $$, s);
4273
+ }
4246
4274
%*/
4247
4275
}
4248
4276
;
@@ -4256,11 +4284,10 @@ string_content : tSTRING_CONTENT
4256
4284
}
4257
4285
string_dvar
4258
4286
{
4259
- /* %%%*/
4260
4287
lex_strterm = $<node>2 ;
4288
+ /* %%%*/
4261
4289
$$ = NEW_EVSTR($3 );
4262
4290
/* %
4263
- lex_strterm = $<node>2;
4264
4291
$$ = dispatch1(string_dvar, $3);
4265
4292
%*/
4266
4293
}
@@ -5158,8 +5185,8 @@ ripper_yylval_id(ID x)
5158
5185
{
5159
5186
return ripper_new_yylval (x, ID2SYM (x), 0 );
5160
5187
}
5161
- # define set_yylval_str (x ) (void )(x )
5162
- # define set_yylval_num (x ) (void )(x )
5188
+ # define set_yylval_str (x ) (yylval.val = (x) )
5189
+ # define set_yylval_num (x ) (yylval.val = ripper_new_yylval((x), 0 , 0 ) )
5163
5190
# define set_yylval_id (x ) (void )(x)
5164
5191
# define set_yylval_name (x ) (void )(yylval.val = ripper_yylval_id(x))
5165
5192
# define set_yylval_literal (x ) (void )(x)
@@ -6273,6 +6300,7 @@ parser_tokadd_string(struct parser_params *parser,
6273
6300
static void
6274
6301
ripper_flush_string_content (struct parser_params *parser, rb_encoding *enc)
6275
6302
{
6303
+ VALUE content = yylval.val ;
6276
6304
if (!NIL_P (parser->delayed )) {
6277
6305
ptrdiff_t len = lex_p - parser->tokp ;
6278
6306
if (len > 0 ) {
@@ -6281,6 +6309,10 @@ ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc)
6281
6309
ripper_dispatch_delayed_token (parser, tSTRING_CONTENT);
6282
6310
parser->tokp = lex_p;
6283
6311
}
6312
+ if (!ripper_is_node_yylval (content))
6313
+ content = ripper_new_yylval (0 , 0 , content);
6314
+ yylval.val = content;
6315
+ ripper_dispatch_scan_event (parser, tSTRING_CONTENT);
6284
6316
}
6285
6317
6286
6318
#define flush_string_content (enc ) ripper_flush_string_content(parser, (enc))
@@ -6367,6 +6399,9 @@ parser_parse_string(struct parser_params *parser, NODE *quote)
6367
6399
}
6368
6400
if (!(func & STR_FUNC_REGEXP)) return tSTRING_END;
6369
6401
set_yylval_num (regx_options ());
6402
+ #ifdef RIPPER
6403
+ ripper_dispatch_scan_event (parser, tREGEXP_END);
6404
+ #endif
6370
6405
return tREGEXP_END;
6371
6406
}
6372
6407
if (space) {
@@ -10223,15 +10258,21 @@ reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *m
10223
10258
NEW_LIT (Qnil)))));
10224
10259
}
10225
10260
10261
+ static VALUE
10262
+ parser_reg_compile (struct parser_params * parser, VALUE str, int options)
10263
+ {
10264
+ reg_fragment_setenc (str, options);
10265
+ return rb_reg_compile (str, options & RE_OPTION_MASK, ruby_sourcefile, ruby_sourceline);
10266
+ }
10267
+
10226
10268
static VALUE
10227
10269
reg_compile_gen (struct parser_params * parser, VALUE str, int options)
10228
10270
{
10229
10271
VALUE re;
10230
10272
VALUE err;
10231
10273
10232
- reg_fragment_setenc (str, options);
10233
10274
err = rb_errinfo ();
10234
- re = rb_reg_compile (str, options & RE_OPTION_MASK, ruby_sourcefile, ruby_sourceline );
10275
+ re = parser_reg_compile (parser, str, options );
10235
10276
if (NIL_P (re)) {
10236
10277
VALUE m = rb_attr_get (rb_errinfo (), idMesg);
10237
10278
rb_set_errinfo (err);
@@ -10246,6 +10287,18 @@ reg_compile_gen(struct parser_params* parser, VALUE str, int options)
10246
10287
return re;
10247
10288
}
10248
10289
10290
+ VALUE
10291
+ rb_parser_reg_compile (struct parser_params * parser, VALUE str, int options, VALUE *errmsg)
10292
+ {
10293
+ VALUE err = rb_errinfo ();
10294
+ VALUE re = parser_reg_compile (parser, str, options);
10295
+ if (NIL_P (re)) {
10296
+ *errmsg = rb_attr_get (rb_errinfo (), idMesg);
10297
+ rb_set_errinfo (err);
10298
+ }
10299
+ return re;
10300
+ }
10301
+
10249
10302
NODE*
10250
10303
rb_parser_append_print (VALUE vparser, NODE *node)
10251
10304
{
0 commit comments