[前][次][番号順一覧][スレッド一覧]

ruby-changes:47076

From: nobu <ko1@a...>
Date: Wed, 28 Jun 2017 13:08:56 +0900 (JST)
Subject: [ruby-changes:47076] nobu:r59191 (trunk): parse.y: flush numeric token

nobu	2017-06-28 13:08:51 +0900 (Wed, 28 Jun 2017)

  New Revision: 59191

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59191

  Log:
    parse.y: flush numeric token
    
    * parse.y (parser_number_literal_suffix, parse_numeric): flush
      numeric token so following unexpected token part is marked.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: parse.y
===================================================================
--- parse.y	(revision 59190)
+++ parse.y	(revision 59191)
@@ -4886,10 +4886,12 @@ ripper_yylval_id(ID x) https://github.com/ruby/ruby/blob/trunk/parse.y#L4886
 #endif
 
 #ifndef RIPPER
+#define numeric_literl_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_literl_flush(p) ((void)0)
 
 #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val))
 
@@ -6516,6 +6518,7 @@ parser_number_literal_suffix(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L6518
 	}
 	if (!ISASCII(c) || ISALPHA(c) || c == '_') {
 	    lex_p = lastp;
+	    numeric_literl_flush(lex_p);
 	    return 0;
 	}
 	pushback(c);
@@ -6529,6 +6532,7 @@ parser_number_literal_suffix(struct pars https://github.com/ruby/ruby/blob/trunk/parse.y#L6532
 	}
 	break;
     }
+    numeric_literl_flush(lex_p);
     return result;
 }
 
@@ -7357,6 +7361,7 @@ parse_numeric(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L7361
     if (nondigit) {
 	char tmp[30];
       trailing_uc:
+	numeric_literl_flush(lex_p - 1);
 	snprintf(tmp, sizeof(tmp), "trailing `%c' in number", nondigit);
 	yyerror(tmp);
     }
@@ -7378,6 +7383,7 @@ parse_numeric(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L7383
 	    }
 	    v = DBL2NUM(d);
 	}
+	numeric_literl_flush(lex_p);
 	return set_number_literal(v, type, suffix);
     }
     suffix = number_literal_suffix(NUM_SUFFIX_ALL);
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 59190)
+++ test/ruby/test_parse.rb	(revision 59191)
@@ -1007,6 +1007,12 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1007
     end
   end
 
+  def test_unexpected_token_after_numeric
+    assert_raise_with_message(SyntaxError, /^    \^~~\z/) do
+      eval('0000xyz')
+    end
+  end
+
 =begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]