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

ruby-changes:55842

From: Takashi <ko1@a...>
Date: Sun, 26 May 2019 14:07:59 +0900 (JST)
Subject: [ruby-changes:55842] Takashi Kokubun: 8aba3b7a04 (trunk): Fix more unintended syntax highlights

https://git.ruby-lang.org/ruby.git/commit/?id=8aba3b7a04

From 8aba3b7a04738c8cebcf3d4ecacd57199d976ae2 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sat, 25 May 2019 21:39:11 -0700
Subject: Fix more unintended syntax highlights

See tests for what kind of things are fixed.

diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index 82f1ca8..269b122 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -15,7 +15,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L15
     CYAN      = 36
 
     TOKEN_KEYWORDS = {
-      on_kw: ['nil', 'self', 'true', 'false'],
+      on_kw: ['nil', 'self', 'true', 'false', '__FILE__'],
       on_const: ['ENV'],
     }
 
@@ -23,19 +23,19 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L23
       TOKEN_SEQ_EXPRS = {
         on_CHAR:            [[BLUE, BOLD],            [Ripper::EXPR_END]],
         on_const:           [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_ENDFN]],
-        on_embexpr_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME]],
-        on_embexpr_end:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ENDFN, Ripper::EXPR_CMDARG]],
+        on_embexpr_beg:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_CMDARG, Ripper::EXPR_FNAME, Ripper::EXPR_ARG]],
+        on_embexpr_end:     [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_CMDARG, Ripper::EXPR_ENDFN, Ripper::EXPR_ARG]],
         on_embvar:          [[RED],                   [Ripper::EXPR_BEG]],
         on_heredoc_beg:     [[RED],                   [Ripper::EXPR_BEG]],
         on_heredoc_end:     [[RED],                   [Ripper::EXPR_BEG]],
         on_ident:           [[BLUE, BOLD],            [Ripper::EXPR_ENDFN]],
         on_int:             [[BLUE, BOLD],            [Ripper::EXPR_END]],
         on_float:           [[MAGENTA, BOLD],         [Ripper::EXPR_END]],
-        on_kw:              [[GREEN],                 [Ripper::EXPR_ARG, Ripper::EXPR_CLASS, Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME]],
+        on_kw:              [[GREEN],                 [Ripper::EXPR_ARG, Ripper::EXPR_CLASS, Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME, Ripper::EXPR_MID]],
         on_label:           [[MAGENTA],               [Ripper::EXPR_LABELED]],
         on_label_end:       [[RED],                   [Ripper::EXPR_BEG]],
-        on_qwords_beg:      [[RED],                   [Ripper::EXPR_BEG]],
-        on_qsymbols_beg:    [[RED],                   [Ripper::EXPR_BEG]],
+        on_qwords_beg:      [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_CMDARG]],
+        on_qsymbols_beg:    [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_CMDARG]],
         on_regexp_beg:      [[RED, BOLD],             [Ripper::EXPR_BEG]],
         on_regexp_end:      [[RED, BOLD],             [Ripper::EXPR_BEG]],
         on_symbeg:          [[YELLOW],                [Ripper::EXPR_FNAME]],
@@ -43,17 +43,8 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L43
         on_tstring_content: [[RED],                   [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_FNAME]],
         on_tstring_end:     [[RED],                   [Ripper::EXPR_END]],
       }
-      SYMBOL_SEQ_OVERRIDES = {
-        on_const:           [YELLOW],
-        on_embexpr_beg:     [YELLOW],
-        on_embexpr_end:     [YELLOW],
-        on_ident:           [YELLOW],
-        on_tstring_content: [YELLOW],
-        on_tstring_end:     [YELLOW],
-      }
     rescue NameError
       TOKEN_SEQ_EXPRS = {}
-      SYMBOL_SEQ_OVERRIDES = {}
     end
 
     class << self
@@ -118,10 +109,12 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L109
       def dispatch_seq(token, expr, str, in_symbol:)
         if token == :on_comment
           [BLUE, BOLD]
+        elsif in_symbol
+          [YELLOW]
         elsif TOKEN_KEYWORDS.fetch(token, []).include?(str)
           [CYAN, BOLD]
         elsif (seq, exprs = TOKEN_SEQ_EXPRS[token]; exprs&.any? { |e| (expr & e) != 0 })
-          SYMBOL_SEQ_OVERRIDES.fetch(in_symbol ? token : nil, seq)
+          seq
         else
           nil
         end
@@ -141,8 +134,8 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L134
         case token
         when :on_symbeg
           @stack << true
-        when :on_ident
-          if @stack.last # Pop only when it's :sym
+        when :on_ident, :on_op, :on_const, :on_ivar
+          if @stack.last # Pop only when it's Symbol
             @stack.pop
             return prev_state
           end
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index e2e4438..9d87b71 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -46,6 +46,18 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L46
         '"#{}"' => "#{RED}\"#{CLEAR}#{RED}\#{#{CLEAR}#{RED}}#{CLEAR}#{RED}\"#{CLEAR}",
         ':"a#{}b"' => "#{YELLOW}:\"#{CLEAR}#{YELLOW}a#{CLEAR}#{YELLOW}\#{#{CLEAR}#{YELLOW}}#{CLEAR}#{YELLOW}b#{CLEAR}#{YELLOW}\"#{CLEAR}",
         ':"a#{ def b; end; \'c\' + "#{ :d }" }e"' => "#{YELLOW}:\"#{CLEAR}#{YELLOW}a#{CLEAR}#{YELLOW}\#{#{CLEAR} #{GREEN}def#{CLEAR} #{BLUE}#{BOLD}b#{CLEAR}; #{GREEN}end#{CLEAR}; #{RED}'#{CLEAR}#{RED}c#{CLEAR}#{RED}'#{CLEAR} + #{RED}\"#{CLEAR}#{RED}\#{#{CLEAR} #{YELLOW}:#{CLEAR}#{YELLOW}d#{CLEAR} #{RED}}#{CLEAR}#{RED}\"#{CLEAR} #{YELLOW}}#{CLEAR}#{YELLOW}e#{CLEAR}#{YELLOW}\"#{CLEAR}",
+        "__FILE__" => "#{CYAN}#{BOLD}__FILE__#{CLEAR}",
+        ":self" => "#{YELLOW}:#{CLEAR}#{YELLOW}self#{CLEAR}",
+        ":class" => "#{YELLOW}:#{CLEAR}#{YELLOW}class#{CLEAR}",
+        "[:>, 3]" => "[#{YELLOW}:#{CLEAR}#{YELLOW}>#{CLEAR}, #{BLUE}#{BOLD}3#{CLEAR}]",
+        ":Hello ? world : nil" => "#{YELLOW}:#{CLEAR}#{YELLOW}Hello#{CLEAR} ? world : #{CYAN}#{BOLD}nil#{CLEAR}",
+        'raise "foo#{bar}baz"' => "raise #{RED}\"#{CLEAR}#{RED}foo#{CLEAR}#{RED}\#{#{CLEAR}bar#{RED}}#{CLEAR}#{RED}baz#{CLEAR}#{RED}\"#{CLEAR}",
+        '["#{obj.inspect}"]' => "[#{RED}\"#{CLEAR}#{RED}\#{#{CLEAR}obj.inspect#{RED}}#{CLEAR}#{RED}\"#{CLEAR}]",
+        'URI.parse "#{}"' => "#{BLUE}#{BOLD}#{UNDERLINE}URI#{CLEAR}.parse #{RED}\"#{CLEAR}#{RED}\#{#{CLEAR}#{RED}}#{CLEAR}#{RED}\"#{CLEAR}",
+        "begin\nrescue\nend" => "#{GREEN}begin#{CLEAR}\n#{GREEN}rescue#{CLEAR}\n#{GREEN}end#{CLEAR}",
+        "foo %w[bar]" => "foo #{RED}%w[#{CLEAR}#{RED}bar#{CLEAR}#{RED}]#{CLEAR}",
+        "foo %i[bar]" => "foo #{RED}%i[#{CLEAR}#{RED}bar#{CLEAR}#{RED}]#{CLEAR}",
+        "foo :@bar, baz" => "foo #{YELLOW}:#{CLEAR}#{YELLOW}@bar#{CLEAR}, baz",
       }.each do |code, result|
         actual = with_term { IRB::Color.colorize_code(code) }
         assert_equal(result, actual, "Case: colorize_code(#{code.dump})\nResult: #{humanized_literal(actual)}")
-- 
cgit v0.10.2


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

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