Skip to content

Commit

Permalink
Handle rest of tokens correctly if no newline at last
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Dec 20, 2020
1 parent 79423d0 commit f3c8eda
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/irb/ruby-lex.rb
Expand Up @@ -63,16 +63,23 @@ def set_input(io, p = nil, &block)
tokens = ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join)
code = String.new
partial_tokens = []
unprocessed_tokens = []
line_num_offset = 0
tokens.each do |t|
code << t[2]
partial_tokens << t
unprocessed_tokens << t
if t[2].include?("\n")
ltype, indent, continue, code_block_open = check_state(code, partial_tokens)
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + line_num_offset)
line_num_offset += 1
unprocessed_tokens = []
end
end
unless unprocessed_tokens.empty?
ltype, indent, continue, code_block_open = check_state(code, unprocessed_tokens)
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + line_num_offset)
end
result
end
end
Expand Down

0 comments on commit f3c8eda

Please sign in to comment.