diff options
author | aycabta <[email protected]> | 2020-12-20 12:20:00 +0900 |
---|---|---|
committer | aycabta <[email protected]> | 2020-12-20 16:23:58 +0900 |
commit | 8b6aaeaddf2d13833c0540490a84741035a3a808 (patch) | |
tree | 8ebb2b1ff8a1c034fc75d4a8f7db8a70bd0810b5 /lib | |
parent | 67ee1cbdd5def5b8e9db987a4a9367ab1d22fcfe (diff) |
[ruby/irb] Handle rest of tokens correctly if no newline at last
https://github.com/ruby/irb/commit/f3c8edad2a
Diffstat (limited to 'lib')
-rw-r--r-- | lib/irb/ruby-lex.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 8507717c63..040c93e8f7 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -63,16 +63,23 @@ class RubyLex 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 |