ruby-changes:47233
From: nobu <ko1@a...>
Date: Mon, 17 Jul 2017 08:45:56 +0900 (JST)
Subject: [ruby-changes:47233] nobu:r59348 (trunk): parse.y: refine invalid Unicode escape message
nobu 2017-07-17 08:45:48 +0900 (Mon, 17 Jul 2017) New Revision: 59348 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59348 Log: parse.y: refine invalid Unicode escape message * parse.y (literal_flush): rename from numeric_literal_flush, as it is not just for numerics now. * parse.y (parser_tokadd_codepoint): show invalid character position, but not the start of Unicode escape. Modified files: trunk/parse.y trunk/test/ruby/test_parse.rb Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 59347) +++ test/ruby/test_parse.rb (revision 59348) @@ -490,7 +490,10 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L490 assert_equal(' ^', e.message.lines.last, mesg) e = assert_syntax_error('"\u{1234"', 'Unicode escape') - assert_match(' ^~~~~~~', e.message.lines.last, mesg) + assert_match(' ^', e.message.lines.last, mesg) + + e = assert_syntax_error('"\u{xxxx}"', 'invalid Unicode escape') + assert_match(' ^', e.message.lines.last, mesg) e = assert_syntax_error('"\M1"', /escape character syntax/) assert_equal(' ^~~', e.message.lines.last, mesg) Index: parse.y =================================================================== --- parse.y (revision 59347) +++ parse.y (revision 59348) @@ -4885,12 +4885,12 @@ ripper_yylval_id(ID x) https://github.com/ruby/ruby/blob/trunk/parse.y#L4885 #endif #ifndef RIPPER -#define numeric_literal_flush(p) (parser->tokp = (p)) +#define literal_flush(p) (parser->tokp = (p)) #define dispatch_scan_event(t) ((void)0) #define dispatch_delayed_token(t) ((void)0) #define has_delayed_token() (0) #else -#define numeric_literal_flush(p) ((void)0) +#define literal_flush(p) ((void)0) #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val)) @@ -5652,6 +5652,7 @@ parser_tokadd_codepoint(struct parser_pa https://github.com/ruby/ruby/blob/trunk/parse.y#L5652 { size_t numlen; int codepoint = scan_hex(lex_p, wide ? 6 : 4, &numlen); + literal_flush(lex_p); lex_p += numlen; if (wide ? (numlen == 0) : (numlen < 4)) { yyerror("invalid Unicode escape"); @@ -5721,7 +5722,7 @@ parser_tokadd_utf8(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L5722 if (c != close_brace) { unterminated: - parser->tokp = lex_p; + literal_flush(lex_p); yyerror("unterminated Unicode escape"); return 0; } @@ -6056,9 +6057,7 @@ parser_tokadd_string(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L6057 } } else if (c == '\\') { -#ifndef RIPPER - parser->tokp = lex_p - 1; -#endif + literal_flush(lex_p - 1); c = nextc(); switch (c) { case '\n': @@ -6532,7 +6531,7 @@ parser_number_literal_suffix(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L6531 } if (!ISASCII(c) || ISALPHA(c) || c == '_') { lex_p = lastp; - numeric_literal_flush(lex_p); + literal_flush(lex_p); return 0; } pushback(c); @@ -6546,7 +6545,7 @@ parser_number_literal_suffix(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L6545 } break; } - numeric_literal_flush(lex_p); + literal_flush(lex_p); return result; } @@ -7375,7 +7374,7 @@ parse_numeric(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L7374 if (nondigit) { char tmp[30]; trailing_uc: - numeric_literal_flush(lex_p - 1); + literal_flush(lex_p - 1); snprintf(tmp, sizeof(tmp), "trailing `%c' in number", nondigit); yyerror(tmp); } @@ -7397,7 +7396,7 @@ parse_numeric(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L7396 } v = DBL2NUM(d); } - numeric_literal_flush(lex_p); + literal_flush(lex_p); return set_number_literal(v, type, suffix); } suffix = number_literal_suffix(NUM_SUFFIX_ALL); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/