[前][次][番号順一覧][スレッド一覧]

ruby-changes:65730

From: Nobuyoshi <ko1@a...>
Date: Fri, 2 Apr 2021 10:53:33 +0900 (JST)
Subject: [ruby-changes:65730] 79af8ce6d7 (master): [ruby/irb] Colorize `__END__` as keyword

https://git.ruby-lang.org/ruby.git/commit/?id=79af8ce6d7

From 79af8ce6d7f46e7e79180dbd6bef6681c1329bd9 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 1 Apr 2021 21:09:32 +0900
Subject: [ruby/irb] Colorize `__END__` as keyword

https://github.com/ruby/irb/commit/9b84018311
---
 lib/irb/color.rb       | 5 ++++-
 test/irb/test_color.rb | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index a054bb2..cfbb3cc 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -64,6 +64,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L64
         on_alias_error:     [[RED, REVERSE],          ALL],
         on_class_name_error:[[RED, REVERSE],          ALL],
         on_param_error:     [[RED, REVERSE],          ALL],
+        on___end__:         [[GREEN],                 ALL],
       }
     rescue NameError
       # Give up highlighting Ripper-incompatible older Ruby
@@ -120,6 +121,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L121
         symbol_state = SymbolState.new
         colored = +''
         length = 0
+        end_seen = false
 
         scan(code, allow_last_error: !complete) do |token, str, expr|
           # IRB::ColorPrinter skips colorizing fragments with any invalid token
@@ -138,10 +140,11 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L140
             end
           end
           length += str.bytesize
+          end_seen = true if token == :on___end__
         end
 
         # give up colorizing incomplete Ripper tokens
-        if length != code.bytesize
+        unless end_seen or length == code.bytesize
           return Reline::Unicode.escape_for_print(code)
         end
 
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index 9976008..a28ae06 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -66,6 +66,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L66
         "\t" => "\t", # not ^I
         "foo(*%W(bar))" => "foo(*#{RED}#{BOLD}%W(#{CLEAR}#{RED}bar#{CLEAR}#{RED}#{BOLD})#{CLEAR})",
         "$stdout" => "#{GREEN}#{BOLD}$stdout#{CLEAR}",
+        "__END__" => "#{GREEN}__END__#{CLEAR}",
       }
 
       # specific to Ruby 2.7+
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]