ruby-changes:34098
From: nobu <ko1@a...>
Date: Tue, 27 May 2014 23:07:01 +0900 (JST)
Subject: [ruby-changes:34098] nobu:r46179 (trunk): parse.y: refine error message
nobu 2014-05-27 23:06:48 +0900 (Tue, 27 May 2014) New Revision: 46179 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46179 Log: parse.y: refine error message * parse.y (parser_number_literal_suffix): refine error message for extra dot and digits. Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_syntax.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46178) +++ ChangeLog (revision 46179) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue May 27 23:06:46 2014 Nobuyoshi Nakada <nobu@r...> + + * parse.y (parser_number_literal_suffix): refine error message for + extra dot and digits. + Tue May 27 22:44:20 2014 Tanaka Akira <akr@f...> * test/rexml: Avoid fd leaks. Index: parse.y =================================================================== --- parse.y (revision 46178) +++ parse.y (revision 46179) @@ -5594,6 +5594,8 @@ parser_str_new(const char *p, long n, rb https://github.com/ruby/ruby/blob/trunk/parse.y#L5594 #define lex_eol_p() (lex_p >= lex_pend) #define peek(c) peek_n((c), 0) #define peek_n(c,n) (lex_p+(n) < lex_pend && (c) == (unsigned char)lex_p[n]) +#define peekc() peekc_n(0) +#define peekc_n(n) (lex_p+(n) < lex_pend ? (unsigned char)lex_p[n] : -1) static inline int parser_nextc(struct parser_params *parser) @@ -6453,6 +6455,14 @@ parser_number_literal_suffix(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L6455 return 0; } pushback(c); + if (c == '.') { + c = peekc_n(1); + if (ISDIGIT(c)) { + yyerror("unexpected fraction part after numeric literal"); + lex_p += 2; + while (parser_is_identchar()) nextc(); + } + } break; } return result; Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 46178) +++ test/ruby/test_syntax.rb (revision 46179) @@ -426,6 +426,15 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L426 end end + def test_unexpected_fraction + msg = /unexpected fraction/ + assert_syntax_error("0x0.0", msg) + assert_syntax_error("0b0.0", msg) + assert_syntax_error("0d0.0", msg) + assert_syntax_error("0o0.0", msg) + assert_syntax_error("0.0.0", msg) + end + private def not_label(x) @result = x; @not_label ||= nil end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/