From c72a2fad9717a6090aa792c31eb0043886d0fb39 Mon Sep 17 00:00:00 2001 From: aycabta Date: Sun, 7 Jun 2020 23:29:01 +0900 Subject: [ruby/irb] Simplify RubyLex.compile_with_errors_suppressed nobu-san reviewed, https://github.com/ruby/irb/pull/106#pullrequestreview-423400033 > How about lexer = Ripper::Lexer.new(";\n#{code}", nil, 0)? > Encoding pragma is effective only at the beginning. > And the semicolon and newline will be skipped because the position is before > the initial pos. I employ the way. Co-authored-by: Nobuyoshi Nakada https://github.com/ruby/irb/commit/e593cc65b7 --- lib/irb/color.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/irb/color.rb') diff --git a/lib/irb/color.rb b/lib/irb/color.rb index d325c8dede..9ee1348671 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -155,8 +155,8 @@ module IRB # :nodoc: pos = [1, 0] verbose, $VERBOSE = $VERBOSE, nil - RubyLex.compile_with_errors_suppressed(code) do |inner_code| - lexer = Ripper::Lexer.new(inner_code) + RubyLex.compile_with_errors_suppressed(code) do |inner_code, line_no| + lexer = Ripper::Lexer.new(inner_code, '(ripper)', line_no) if lexer.respond_to?(:scan) # Ruby 2.7+ lexer.scan.each do |elem| str = elem.tok -- cgit v1.2.3