mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
716ce65138
commit
f14f0d3464
2 changed files with 17 additions and 8 deletions
|
@ -262,9 +262,18 @@ class RubyLex
|
||||||
end
|
end
|
||||||
|
|
||||||
def lex
|
def lex
|
||||||
until (((tk = token).kind_of?(TkNL) || tk.kind_of?(TkEND_OF_SCRIPT)) &&
|
continue = @continue
|
||||||
!@continue or
|
while tk = token
|
||||||
tk.nil?)
|
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
|
end
|
||||||
line = get_readed
|
line = get_readed
|
||||||
if line == "" and tk.kind_of?(TkEND_OF_SCRIPT) || tk.nil?
|
if line == "" and tk.kind_of?(TkEND_OF_SCRIPT) || tk.nil?
|
||||||
|
|
|
@ -55,15 +55,15 @@ module TestIRB
|
||||||
src, lineno = "#{<<-"begin;"}#{<<~'end;'}", __LINE__+1
|
src, lineno = "#{<<-"begin;"}#{<<~'end;'}", __LINE__+1
|
||||||
begin;
|
begin;
|
||||||
# #;# LTYPE:INDENT:CONTINUE
|
# #;# LTYPE:INDENT:CONTINUE
|
||||||
x #;# -:0:- # FIXME: a comment should not `continue'
|
x #;# -:0:-
|
||||||
x( #;# -:0:-
|
x( #;# -:0:-
|
||||||
) #;# -:1:*
|
) #;# -:1:*
|
||||||
a \ #;# -:0:-
|
a \ #;# -:0:-
|
||||||
#;# -:0:*
|
#;# -:0:*
|
||||||
a; #;# -:0:-
|
a; #;# -:0:-
|
||||||
a #;# -:0:- # FIXME: a semicolon should not `continue'
|
a #;# -:0:-
|
||||||
#;# -:0:-
|
#;# -:0:-
|
||||||
a #;# -:0:- # FIXME: an empty line should not `continue'
|
a #;# -:0:-
|
||||||
a = #;# -:0:-
|
a = #;# -:0:-
|
||||||
' #;# -:0:*
|
' #;# -:0:*
|
||||||
' #;# ':0:*
|
' #;# ':0:*
|
||||||
|
@ -73,11 +73,11 @@ module TestIRB
|
||||||
" #;# -:1:-
|
" #;# -:1:-
|
||||||
" #;# ":1:-
|
" #;# ":1:-
|
||||||
begin #;# -:1:-
|
begin #;# -:1:-
|
||||||
a #;# -:2:- # FIXME: the first line should not be `continue'd
|
a #;# -:2:-
|
||||||
a #;# -:2:-
|
a #;# -:2:-
|
||||||
end #;# -:2:-
|
end #;# -:2:-
|
||||||
else #;# -:1:-
|
else #;# -:1:-
|
||||||
nil #;# -:1:- # FIXME: just after `else' should not be `continue'd
|
nil #;# -:1:-
|
||||||
end #;# -:1:-
|
end #;# -:1:-
|
||||||
end;
|
end;
|
||||||
top_level_statement(src.gsub(/[ \t]*#;#.*/, ''))
|
top_level_statement(src.gsub(/[ \t]*#;#.*/, ''))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue