diff options
author | tompng <tomoyapenguin@gmail.com> | 2022-09-27 13:14:42 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-10-01 04:17:15 +0900 |
commit | 641310ce371bd220a5ddd5e54a86979f4055608b (patch) | |
tree | 8010afde2aecd9aa2d11bdbbad7194d57f95861b /lib | |
parent | 31461c7e0eab4963ccc8649ea8ebf27979132c0c (diff) |
[ruby/irb] Fix ripper_lex_without_warning duplicated heredoc token
https://github.com/ruby/irb/commit/45b539af39
Diffstat (limited to 'lib')
-rw-r--r-- | lib/irb/ruby-lex.rb | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 29862f5507..766e797fca 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -152,17 +152,13 @@ class RubyLex lexer = Ripper::Lexer.new(inner_code, '-', line_no) if lexer.respond_to?(:scan) # Ruby 2.7+ tokens = [] - pos_to_index = {} lexer.scan.each do |t| next if t.pos.first == 0 - if pos_to_index.has_key?(t.pos) - index = pos_to_index[t.pos] - found_tk = tokens[index] - if ERROR_TOKENS.include?(found_tk.event) && !ERROR_TOKENS.include?(t.event) - tokens[index] = t - end + prev_tk = tokens.last + position_overlapped = prev_tk && t.pos[0] == prev_tk.pos[0] && t.pos[1] < prev_tk.pos[1] + prev_tk.tok.bytesize + if position_overlapped + tokens[-1] = t if ERROR_TOKENS.include?(prev_tk.event) && !ERROR_TOKENS.include?(t.event) else - pos_to_index[t.pos] = tokens.size tokens << t end end |