diff options
-rw-r--r-- | lib/irb/ruby-lex.rb | 15 | ||||
-rw-r--r-- | test/irb/test_ruby-lex.rb | 10 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 3329c02284..fb7e08099f 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -262,9 +262,18 @@ class RubyLex 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? diff --git a/test/irb/test_ruby-lex.rb b/test/irb/test_ruby-lex.rb index 7e4d486b8d..b07b4a2eb6 100644 --- a/test/irb/test_ruby-lex.rb +++ b/test/irb/test_ruby-lex.rb @@ -55,15 +55,15 @@ module TestIRB 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 " #;# -: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]*#;#.*/, '')) |