diff options
author | st0012 <[email protected]> | 2022-09-30 23:08:36 +0100 |
---|---|---|
committer | git <[email protected]> | 2022-10-03 04:59:49 +0900 |
commit | 55e2116f2c47db6c4e3323b7b89f0088efbb46ad (patch) | |
tree | eea34ac16648dd3e0194a8de2d043b712889c841 /lib/irb/ruby-lex.rb | |
parent | ded895baa96cb9622fcd44d308fb48341565605b (diff) |
[ruby/irb] Refactor ripper_lex_without_warning
https://github.com/ruby/irb/commit/0db0a8ddc5
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r-- | lib/irb/ruby-lex.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 766e797fca..77e7842469 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -139,7 +139,7 @@ class RubyLex def self.ripper_lex_without_warning(code, context: nil) verbose, $VERBOSE = $VERBOSE, nil if context - lvars = context&.workspace&.binding&.local_variables + lvars = context.workspace&.binding&.local_variables if lvars && !lvars.empty? code = "#{lvars.join('=')}=nil\n#{code}" line_no = 0 @@ -147,12 +147,11 @@ class RubyLex line_no = 1 end end - tokens = nil + compile_with_errors_suppressed(code, line_no: line_no) do |inner_code, line_no| lexer = Ripper::Lexer.new(inner_code, '-', line_no) if lexer.respond_to?(:scan) # Ruby 2.7+ - tokens = [] - lexer.scan.each do |t| + lexer.scan.each_with_object([]) do |t, tokens| next if t.pos.first == 0 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 @@ -163,10 +162,9 @@ class RubyLex end end else - tokens = lexer.parse.reject { |it| it.pos.first == 0 } + lexer.parse.reject { |it| it.pos.first == 0 } end end - tokens ensure $VERBOSE = verbose end |