diff options
author | aycabta <aycabta@gmail.com> | 2020-06-01 08:53:07 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2020-07-22 02:31:46 +0900 |
commit | 78ccab25306d15c325baa0761d9505ac23956f22 (patch) | |
tree | ac463593c2efd8e924e43cea302d154e680ed0a6 /lib/irb/color.rb | |
parent | 48eb1ad2c3aa1a14bd8ef61cbd72a791b0b67418 (diff) | |
download | ruby-78ccab25306d15c325baa0761d9505ac23956f22.tar.gz |
[ruby/irb] Suppress incomplete coding magic comment error
https://github.com/ruby/irb/commit/6a457edbd1
Diffstat (limited to 'lib/irb/color.rb')
-rw-r--r-- | lib/irb/color.rb | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/irb/color.rb b/lib/irb/color.rb index d2b9674a71..d325c8dede 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -155,27 +155,29 @@ module IRB # :nodoc: pos = [1, 0] verbose, $VERBOSE = $VERBOSE, nil - lexer = Ripper::Lexer.new(code) - if lexer.respond_to?(:scan) # Ruby 2.7+ - lexer.scan.each do |elem| - str = elem.tok - next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message - next if ([elem.pos[0], elem.pos[1] + str.bytesize] <=> pos) <= 0 - - str.each_line do |line| - if line.end_with?("\n") - pos[0] += 1 - pos[1] = 0 - else - pos[1] += line.bytesize + RubyLex.compile_with_errors_suppressed(code) do |inner_code| + lexer = Ripper::Lexer.new(inner_code) + if lexer.respond_to?(:scan) # Ruby 2.7+ + lexer.scan.each do |elem| + str = elem.tok + next if allow_last_error and /meets end of file|unexpected end-of-input/ =~ elem.message + next if ([elem.pos[0], elem.pos[1] + str.bytesize] <=> pos) <= 0 + + str.each_line do |line| + if line.end_with?("\n") + pos[0] += 1 + pos[1] = 0 + else + pos[1] += line.bytesize + end end - end - yield(elem.event, str, elem.state) - end - else - lexer.parse.each do |elem| - yield(elem.event, elem.tok, elem.state) + yield(elem.event, str, elem.state) + end + else + lexer.parse.each do |elem| + yield(elem.event, elem.tok, elem.state) + end end end $VERBOSE = verbose |