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

ruby-changes:46304

From: nobu <ko1@a...>
Date: Thu, 20 Apr 2017 20:07:07 +0900 (JST)
Subject: [ruby-changes:46304] nobu:r58418 (trunk): ruby-lex.rb: fix continued line conditions

nobu	2017-04-20 20:07:02 +0900 (Thu, 20 Apr 2017)

  New Revision: 58418

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

  Log:
    ruby-lex.rb: fix continued line conditions
    
    * lib/irb/ruby-lex.rb (RubyLex#lex): fix conditions for continued
      line; empty lines, a semicolon, first line in `begin` block,
      just after `else` are not continued.

  Modified files:
    trunk/lib/irb/ruby-lex.rb
    trunk/test/irb/test_ruby-lex.rb
Index: test/irb/test_ruby-lex.rb
===================================================================
--- test/irb/test_ruby-lex.rb	(revision 58417)
+++ test/irb/test_ruby-lex.rb	(revision 58418)
@@ -55,15 +55,15 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby-lex.rb#L55
       src, lineno = "#{<<-"begin;"}#{<<~'end;'}", __LINE__+1
       begin;
         #            #;# LTYPE:INDENT:CONTINUE
-        x            #;# -:0:- # FIXME: a comment should not `continue'
+        x            #;# -:0:-
         x(           #;# -:0:-
         )            #;# -:1:*
         a \          #;# -:0:-
                      #;# -:0:*
         a;           #;# -:0:-
-        a            #;# -:0:- # FIXME: a semicolon should not `continue'
+        a            #;# -:0:-
                      #;# -:0:-
-        a            #;# -:0:- # FIXME: an empty line should not `continue'
+        a            #;# -:0:-
         a =          #;# -:0:-
           '          #;# -:0:*
           '          #;# ':0:*
@@ -73,11 +73,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby-lex.rb#L73
           "          #;# -:1:-
           "          #;# ":1:-
           begin      #;# -:1:-
-            a        #;# -:2:- # FIXME: the first line should not be `continue'd
+            a        #;# -:2:-
             a        #;# -:2:-
           end        #;# -:2:-
         else         #;# -:1:-
-          nil        #;# -:1:- # FIXME: just after `else' should not be `continue'd
+          nil        #;# -:1:-
         end          #;# -:1:-
       end;
       top_level_statement(src.gsub(/[ \t]*#;#.*/, ''))
Index: lib/irb/ruby-lex.rb
===================================================================
--- lib/irb/ruby-lex.rb	(revision 58417)
+++ lib/irb/ruby-lex.rb	(revision 58418)
@@ -262,9 +262,18 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L262
   end
 
   def lex
-    until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
-        !@continue or
-        tk.nil?)
+    continue = @continue
+    while tk = token
+      case tk
+      when TkNL, TkEND_OF_SCRIPT
+        @continue = continue unless continue.nil?
+        break unless @continue
+      when TkSPACE, TkCOMMENT
+      when TkSEMICOLON, TkBEGIN, TkELSE
+        @continue = continue = false
+      else
+        continue = nil
+      end
     end
     line = get_readed
     if line == "" and tk.kind_of?(TkEND_OF_SCRIPT) || tk.nil?

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

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