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

ruby-changes:50919

From: nobu <ko1@a...>
Date: Mon, 9 Apr 2018 20:09:35 +0900 (JST)
Subject: [ruby-changes:50919] nobu:r63126 (trunk): parse.y: extra error message after no digits

nobu	2018-04-09 20:09:30 +0900 (Mon, 09 Apr 2018)

  New Revision: 63126

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

  Log:
    parse.y: extra error message after no digits
    
    * parse.y (no_digits): return tINTEGER instead of unexpected
      end-of-input, to get rid of extra error messages.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_literal.rb
Index: parse.y
===================================================================
--- parse.y	(revision 63125)
+++ parse.y	(revision 63126)
@@ -6841,6 +6841,15 @@ parse_rational(struct parser_params *p, https://github.com/ruby/ruby/blob/trunk/parse.y#L6841
 }
 
 static enum yytokentype
+no_digits(struct parser_params *p)
+{
+    yyerror0("numeric literal without digits");
+    if (peek(p, '_')) nextc(p);
+    /* dummy 0, for tUMINUS_NUM at numeric */
+    return set_integer_literal(p, INT2FIX(0), 0);
+}
+
+static enum yytokentype
 parse_numeric(struct parser_params *p, int c)
 {
     int is_float, seen_point, seen_e, nondigit;
@@ -6854,7 +6863,6 @@ parse_numeric(struct parser_params *p, i https://github.com/ruby/ruby/blob/trunk/parse.y#L6863
 	c = nextc(p);
     }
     if (c == '0') {
-#define no_digits() do {yyerror0("numeric literal without digits"); return 0;} while (0)
 	int start = toklen(p);
 	c = nextc(p);
 	if (c == 'x' || c == 'X') {
@@ -6875,7 +6883,7 @@ parse_numeric(struct parser_params *p, i https://github.com/ruby/ruby/blob/trunk/parse.y#L6883
 	    pushback(p, c);
 	    tokfix(p);
 	    if (toklen(p) == start) {
-		no_digits();
+		return no_digits(p);
 	    }
 	    else if (nondigit) goto trailing_uc;
 	    suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
@@ -6899,7 +6907,7 @@ parse_numeric(struct parser_params *p, i https://github.com/ruby/ruby/blob/trunk/parse.y#L6907
 	    pushback(p, c);
 	    tokfix(p);
 	    if (toklen(p) == start) {
-		no_digits();
+		return no_digits(p);
 	    }
 	    else if (nondigit) goto trailing_uc;
 	    suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
@@ -6923,7 +6931,7 @@ parse_numeric(struct parser_params *p, i https://github.com/ruby/ruby/blob/trunk/parse.y#L6931
 	    pushback(p, c);
 	    tokfix(p);
 	    if (toklen(p) == start) {
-		no_digits();
+		return no_digits(p);
 	    }
 	    else if (nondigit) goto trailing_uc;
 	    suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
@@ -6937,7 +6945,7 @@ parse_numeric(struct parser_params *p, i https://github.com/ruby/ruby/blob/trunk/parse.y#L6945
 	    /* prefixed octal */
 	    c = nextc(p);
 	    if (c == -1 || c == '_' || !ISDIGIT(c)) {
-		no_digits();
+		return no_digits(p);
 	    }
 	}
 	if (c >= '0' && c <= '7') {
Index: test/ruby/test_literal.rb
===================================================================
--- test/ruby/test_literal.rb	(revision 63125)
+++ test/ruby/test_literal.rb	(revision 63126)
@@ -516,11 +516,12 @@ class TestRubyLiteral < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_literal.rb#L516
       }
     }
     bug2407 = '[ruby-dev:39798]'
-    head.each {|h|
-      if /^0/ =~ h
-        assert_syntax_error("#{h}_", /numeric literal without digits\Z/, "#{bug2407}: #{h.inspect}")
+    head.grep_v(/^0/) do |s|
+      head.grep(/^0/) do |h|
+        h = "#{s}#{h}_"
+        assert_syntax_error(h, /numeric literal without digits\Z/, "#{bug2407}: #{h.inspect}")
       end
-    }
+    end
   end
 
   def test_float

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

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