From 897901283c79e5f5f33656abdd453dc272268748 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 26 May 2019 10:29:20 -0700 Subject: Refactor IRB color dispatch The reason why we were checking lexer state in addition to token was that we do not want to colorize local variable, method call, etc., while they share the :on_ident token with a name of method definition which should be colored as blue. It means that we're concerned about the lexer state only for :on_ident. Thus we can skip checking lexer state for non-:on_ident tokens. This refactoring is based on that idea. Also, now we manage Ripper's lexer state as Integer (use `|` if you need to check multiple states). It should be faster than using Array of Integer because #any? block call is not needed. --- test/irb/test_color.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/irb') diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index 98dfbb1e8a..577c737662 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -30,7 +30,7 @@ module TestIRB "['foo', :bar]" => "[#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR}, #{YELLOW}:#{CLEAR}#{YELLOW}bar#{CLEAR}]", "class A; end" => "#{GREEN}class#{CLEAR} #{BLUE}#{BOLD}#{UNDERLINE}A#{CLEAR}; #{GREEN}end#{CLEAR}", "def self.foo; bar; end" => "#{GREEN}def#{CLEAR} #{CYAN}#{BOLD}self#{CLEAR}.#{BLUE}#{BOLD}foo#{CLEAR}; bar; #{GREEN}end#{CLEAR}", - 'ERB.new("a#{nil}b", trim_mode: "-")' => "#{BLUE}#{BOLD}#{UNDERLINE}ERB#{CLEAR}.new(#{RED}\"#{CLEAR}#{RED}a#{CLEAR}#{RED}\#{#{CLEAR}#{CYAN}#{BOLD}nil#{CLEAR}#{RED}}#{CLEAR}#{RED}b#{CLEAR}#{RED}\"#{CLEAR}, #{MAGENTA}trim_mode:#{CLEAR} #{RED}\"#{CLEAR}#{RED}-#{CLEAR}#{RED}\"#{CLEAR})", + 'erb = ERB.new("a#{nil}b", trim_mode: "-")' => "erb = #{BLUE}#{BOLD}#{UNDERLINE}ERB#{CLEAR}.new(#{RED}\"#{CLEAR}#{RED}a#{CLEAR}#{RED}\#{#{CLEAR}#{CYAN}#{BOLD}nil#{CLEAR}#{RED}}#{CLEAR}#{RED}b#{CLEAR}#{RED}\"#{CLEAR}, #{MAGENTA}trim_mode:#{CLEAR} #{RED}\"#{CLEAR}#{RED}-#{CLEAR}#{RED}\"#{CLEAR})", "# comment" => "#{BLUE}#{BOLD}# comment#{CLEAR}", "yield(hello)" => "#{GREEN}yield#{CLEAR}(hello)", '"##@var]"' => "#{RED}\"#{CLEAR}#{RED}##{CLEAR}#{RED}##{CLEAR}@var#{RED}]#{CLEAR}#{RED}\"#{CLEAR}", -- cgit v1.2.3