ruby-changes:47081
From: nobu <ko1@a...>
Date: Wed, 28 Jun 2017 15:13:04 +0900 (JST)
Subject: [ruby-changes:47081] nobu:r59196 (trunk): parse.y: fix token
nobu 2017-06-28 15:13:00 +0900 (Wed, 28 Jun 2017) New Revision: 59196 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59196 Log: parse.y: fix token * parse.y (parser_parse_string): return proper token tREGEXP_END at unterminated regexp. [Bug #13363] Modified files: trunk/parse.y trunk/test/ruby/test_parse.rb Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 59195) +++ test/ruby/test_parse.rb (revision 59196) @@ -1022,6 +1022,14 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1022 assert_operator(line, :end_with?, "...\n") end + def test_unterminated_regexp_error + e = assert_raise(SyntaxError) do + eval("/x") + end.message + assert_match(/unterminated regexp meets end of file/, e) + assert_not_match(/unexpected tSTRING_END/, e) + end + =begin def test_past_scope_variable assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} Index: parse.y =================================================================== --- parse.y (revision 59195) +++ parse.y (revision 59196) @@ -5461,7 +5461,7 @@ rb_parser_compile_file_path(VALUE vparse https://github.com/ruby/ruby/blob/trunk/parse.y#L5461 #define STR_FUNC_SYMBOL 0x10 #define STR_FUNC_INDENT 0x20 #define STR_FUNC_LABEL 0x40 -#define STR_TERM_END -1 +#define STR_FUNC_TERM 0x8000 enum string_type { str_label = STR_FUNC_LABEL, @@ -6237,7 +6237,9 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6237 int c, space = 0; rb_encoding *enc = current_enc; - if (term == STR_TERM_END) return tSTRING_END; + if (func & STR_FUNC_TERM) { + return func & STR_FUNC_REGEXP ? tREGEXP_END : tSTRING_END; + } c = nextc(); if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) { do {c = nextc();} while (ISSPACE(c)); @@ -6245,7 +6247,7 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6247 } if (c == term && !quote->nd_nest) { if (func & STR_FUNC_QWORDS) { - quote->u2.id = STR_TERM_END; + quote->nd_func |= STR_FUNC_TERM; return ' '; } return parser_string_term(parser, func); @@ -6271,7 +6273,7 @@ parser_parse_string(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6273 else { compile_error(PARSER_ARG "unterminated string meets end of file"); } - quote->u2.id = STR_TERM_END; + quote->nd_func |= STR_FUNC_TERM; } } @@ -6704,7 +6706,7 @@ parser_here_document(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6706 yylval.val, str); #endif heredoc_restore(lex_strterm); - lex_strterm = NEW_STRTERM(func, STR_TERM_END, 0); + lex_strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0); set_yylval_str(str); return tSTRING_CONTENT; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/