ruby-changes:55837
From: Takashi <ko1@a...>
Date: Sun, 26 May 2019 00:20:28 +0900 (JST)
Subject: [ruby-changes:55837] Takashi Kokubun: 98be203704 (trunk): Support some unhandled syntax highlight
https://git.ruby-lang.org/ruby.git/commit/?id=98be203704 From 98be203704e98c53b2d3b939b10a0d765c76d53d Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Sat, 25 May 2019 08:01:51 -0700 Subject: Support some unhandled syntax highlight Heredoc, %i, :Foo, { 'a': ... }, ... :'a' is still half-broken. diff --git a/lib/irb/color.rb b/lib/irb/color.rb index ad5b203..7bd1799 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -21,21 +21,25 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L21 begin TOKEN_SEQ_EXPRS = { on_CHAR: [[BLUE, BOLD], [Ripper::EXPR_END]], - on_const: [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]], + on_const: [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_ENDFN]], on_embexpr_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END]], on_embexpr_end: [[RED], [Ripper::EXPR_END, Ripper::EXPR_ENDFN, Ripper::EXPR_CMDARG]], 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_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_regexp_beg: [[RED, BOLD], [Ripper::EXPR_BEG]], on_regexp_end: [[RED, BOLD], [Ripper::EXPR_BEG]], on_symbeg: [[BLUE, BOLD], [Ripper::EXPR_FNAME]], on_tstring_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]], - on_tstring_content: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]], + 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]], } rescue NameError diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index 1d7d74e..95ed190 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L1 # frozen_string_literal: false require 'test/unit' require 'irb/color' +require 'rubygems' require 'stringio' module TestIRB @@ -36,6 +37,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L37 "4.5.6" => "4.5.6", "[1]]]" => "[1]]]", "\e[0m\n" => "^[[#{BLUE}#{BOLD}0#{CLEAR}m\n", + "%w[a b]" => "#{RED}%w[#{CLEAR}#{RED}a#{CLEAR} #{RED}b#{CLEAR}#{RED}]#{CLEAR}", + "%i[c d]" => "#{RED}%i[#{CLEAR}#{RED}c#{CLEAR} #{RED}d#{CLEAR}#{RED}]#{CLEAR}", + "{'a': 1}" => "{#{RED}'#{CLEAR}#{RED}a#{CLEAR}#{RED}':#{CLEAR} #{BLUE}#{BOLD}1#{CLEAR}}", + ":Struct" => "#{BLUE}#{BOLD}:#{CLEAR}#{BLUE}#{BOLD}#{UNDERLINE}Struct#{CLEAR}", + "<<EOS\nhere\nEOS" => "#{RED}<<EOS#{CLEAR}\n#{RED}here#{CLEAR}\n#{RED}EOS#{CLEAR}", }.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/