ruby-changes:43737
From: nobu <ko1@a...>
Date: Wed, 3 Aug 2016 21:31:34 +0900 (JST)
Subject: [ruby-changes:43737] nobu:r55810 (trunk): parse.y: reg_fragment_enc_error
nobu 2016-08-03 21:31:25 +0900 (Wed, 03 Aug 2016) New Revision: 55810 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55810 Log: parse.y: reg_fragment_enc_error * parse.y (reg_fragment_enc_error): compile_error is different between parser and ripper. [ruby-core:76397] [Bug #12651] Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ripper/test_ripper.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 55809) +++ ChangeLog (revision 55810) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Aug 3 21:31:23 2016 Nobuyoshi Nakada <nobu@r...> + + * parse.y (reg_fragment_enc_error): compile_error is different + between parser and ripper. [ruby-core:76397] [Bug #12651] + Wed Aug 3 17:15:06 2016 Nobuyoshi Nakada <nobu@r...> * object.c (rb_obj_clone2): restrict freeze option to true other Index: parse.y =================================================================== --- parse.y (revision 55809) +++ parse.y (revision 55810) @@ -549,11 +549,15 @@ static VALUE new_op_assign_gen(struct pa https://github.com/ruby/ruby/blob/trunk/parse.y#L549 static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs); #define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs)) +static VALUE parser_reg_compile(struct parser_params*, VALUE, int, VALUE *); + #endif /* !RIPPER */ #define new_op_assign(lhs, op, rhs) new_op_assign_gen(parser, (lhs), (op), (rhs)) -RUBY_FUNC_EXPORTED VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options, VALUE *errmsg); +RUBY_FUNC_EXPORTED VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options); +RUBY_FUNC_EXPORTED int rb_reg_fragment_setenc(struct parser_params*, VALUE, int); + static ID formal_argument_gen(struct parser_params*, ID); #define formal_argument(id) formal_argument_gen(parser, (id)) @@ -4052,7 +4056,7 @@ regexp : tREGEXP_BEG regexp_contents tR https://github.com/ruby/ruby/blob/trunk/parse.y#L4056 $3 = RNODE(opt)->nd_rval; options = (int)RNODE(opt)->nd_tag; } - if (src && NIL_P(rb_parser_reg_compile(parser, src, options, &err))) { + if (src && NIL_P(parser_reg_compile(parser, src, options, &err))) { compile_error(PARSER_ARG "%"PRIsVALUE, err); } $$ = dispatch2(regexp_literal, $2, $3); @@ -10536,9 +10540,17 @@ dvar_curr_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L10540 vtable_included(lvtbl->vars, id)); } -#ifndef RIPPER static void -reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options) +reg_fragment_enc_error(struct parser_params* parser, VALUE str, int c) +{ + compile_error(PARSER_ARG + "regexp encoding option '%c' differs from source encoding '%s'", + c, rb_enc_name(rb_enc_get(str))); +} + +#ifndef RIPPER +int +rb_reg_fragment_setenc(struct parser_params* parser, VALUE str, int options) { int c = RE_OPTION_ENCODING_IDX(options); @@ -10568,12 +10580,17 @@ reg_fragment_setenc_gen(struct parser_pa https://github.com/ruby/ruby/blob/trunk/parse.y#L10580 rb_enc_associate(str, rb_ascii8bit_encoding()); } } - return; + return 0; error: - compile_error(PARSER_ARG - "regexp encoding option '%c' differs from source encoding '%s'", - c, rb_enc_name(rb_enc_get(str))); + return c; +} + +static void +reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options) +{ + int c = rb_reg_fragment_setenc(parser, str, options); + if (c) reg_fragment_enc_error(parser, str, c); } static int @@ -10640,6 +10657,12 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/parse.y#L10657 parser_reg_compile(struct parser_params* parser, VALUE str, int options) { reg_fragment_setenc(str, options); + return rb_parser_reg_compile(parser, str, options); +} + +VALUE +rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options) +{ return rb_reg_compile(str, options & RE_OPTION_MASK, ruby_sourcefile, ruby_sourceline); } @@ -10664,19 +10687,24 @@ reg_compile_gen(struct parser_params* pa https://github.com/ruby/ruby/blob/trunk/parse.y#L10687 } return re; } - -VALUE -rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options, VALUE *errmsg) +#else +static VALUE +parser_reg_compile(struct parser_params* parser, VALUE str, int options, VALUE *errmsg) { VALUE err = rb_errinfo(); - VALUE re = parser_reg_compile(parser, str, options); + VALUE re; + int c = rb_reg_fragment_setenc(parser, str, options); + if (c) reg_fragment_enc_error(parser, str, c); + re = rb_parser_reg_compile(parser, str, options); if (NIL_P(re)) { *errmsg = rb_attr_get(rb_errinfo(), idMesg); rb_set_errinfo(err); } return re; } +#endif +#ifndef RIPPER NODE* rb_parser_append_print(VALUE vparser, NODE *node) { Index: test/ripper/test_ripper.rb =================================================================== --- test/ripper/test_ripper.rb (revision 55809) +++ test/ripper/test_ripper.rb (revision 55810) @@ -72,4 +72,30 @@ class TestRipper::Ripper < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ripper/test_ripper.rb#L72 ripper.parse assert_not_predicate(ripper, :error?, bug11932) end + + def test_regexp_enc_error + assert_separately(%w[-rripper], "#{<<-"begin;"}\n#{<<-"end;"}") + begin; + bug12651 = '[ruby-core:76397] [Bug #12651]' + src = <<-END +<%- @title = '\u{5bff 9650 7121}' -%> +<%- content_for :foo, render(partial: 'bar', locals: {baz: 2}) -%> + +<div class="dead beef"> + <h2 class="dead beef">\u{5bff 9650 7121}</h2> +</div> +<div class="dead beef">\u{5bff 9650 7121 3002}<br class="dead beef">\u{5bff 9650 7121 3002}</div> + +<div class="dead beef"> + <div class="dead beef"> + <label class="dead beef">\u{5bff 9650 7121}</label> + <div class="dead beef"> + <div class="dead beef"><%= @baz %></div> + </div> + </div> +</div> + END + assert_nil(Ripper.sexp(src), bug12651) + end; + end end if ripper_test -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/