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

ruby-changes:30145

From: nobu <ko1@a...>
Date: Fri, 26 Jul 2013 23:05:45 +0900 (JST)
Subject: [ruby-changes:30145] nobu:r42197 (trunk): parse.y: separate numeric literal

nobu	2013-07-26 23:05:34 +0900 (Fri, 26 Jul 2013)

  New Revision: 42197

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42197

  Log:
    parse.y: separate numeric literal
    
    * parse.y (parser_yylex): separate numeric literal from succeeding
      token, and treat 'e' as floating point number only if followed by
      exponent part.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42196)
+++ ChangeLog	(revision 42197)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul 26 23:05:27 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_yylex): separate numeric literal from succeeding
+	  token, and treat 'e' as floating point number only if followed by
+	  exponent part.
+
 Fri Jul 26 22:14:10 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_exec.h (CHECK_VM_STACK_OVERFLOW_FOR_INSN): surround with
Index: parse.y
===================================================================
--- parse.y	(revision 42196)
+++ parse.y	(revision 42197)
@@ -7542,14 +7542,18 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7542
 		    if (seen_e) {
 			goto decode_num;
 		    }
-		    tokadd(c);
-		    seen_e++;
-		    is_float++;
 		    nondigit = c;
 		    c = nextc();
-		    if (c != '-' && c != '+') continue;
+		    if (c != '-' && c != '+' && !ISDIGIT(c)) {
+			pushback(c);
+			nondigit = 0;
+			goto decode_num;
+		    }
+		    tokadd(nondigit);
+		    seen_e++;
+		    is_float++;
 		    tokadd(c);
-		    nondigit = c;
+		    nondigit = (c == '-' || c == '+') ? c : 0;
 		    break;
 
 		  case '_':	/* `_' in number just ignored */
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 42196)
+++ test/ruby/test_syntax.rb	(revision 42197)
@@ -363,6 +363,13 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L363
     assert_constant_reassignment_toplevel("11",    "+",  %w[53], already)
   end
 
+  def test_integer_suffix
+    ["1if true", "begin 1end"].each do |src|
+      assert_valid_syntax(src)
+      assert_equal(1, eval(src), src)
+    end
+  end
+
   private
 
   def not_label(x) @result = x; @not_label ||= nil end

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

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