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

ruby-changes:67670

From: aycabta <ko1@a...>
Date: Fri, 10 Sep 2021 04:59:36 +0900 (JST)
Subject: [ruby-changes:67670] f085a6fb69 (master): [ruby/irb] Support symbol with backtick

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

From f085a6fb6953a23e555cae7ffe4274927c6b0961 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Wed, 8 Sep 2021 22:19:52 +0900
Subject: [ruby/irb] Support symbol with backtick

https://github.com/ruby/irb/commit/0aa2425883
---
 lib/irb/ruby-lex.rb       | 18 +++++++++++-------
 test/irb/test_ruby_lex.rb | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index f744f36..e281169 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -708,6 +708,9 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L708
     while i < tokens.size
       t = tokens[i]
       case t[1]
+      when *end_type.last
+        start_token.pop
+        end_type.pop
       when :on_tstring_beg
         start_token << t
         end_type << [:on_tstring_end, :on_label_end]
@@ -715,10 +718,14 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L718
         start_token << t
         end_type << :on_regexp_end
       when :on_symbeg
-        acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw on_int}
-        if (i + 1) < tokens.size and acceptable_single_tokens.all?{ |st| tokens[i + 1][1] != st }
-          start_token << t
-          end_type << :on_tstring_end
+        acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw on_int on_backtick}
+        if (i + 1) < tokens.size
+          if acceptable_single_tokens.all?{ |st| tokens[i + 1][1] != st }
+            start_token << t
+            end_type << :on_tstring_end
+          else
+            i += 1
+          end
         end
       when :on_backtick
         start_token << t
@@ -729,9 +736,6 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L736
       when :on_heredoc_beg
         start_token << t
         end_type << :on_heredoc_end
-      when *end_type.last
-        start_token.pop
-        end_type.pop
       end
       i += 1
     end
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index d31d38d..e255720 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -136,6 +136,26 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L136
       end
     end
 
+    def test_symbols
+      input_with_correct_indents = [
+        Row.new(%q(:a), nil, 0),
+        Row.new(%q(:A), nil, 0),
+        Row.new(%q(:+), nil, 0),
+        Row.new(%q(:@@a), nil, 0),
+        Row.new(%q(:@a), nil, 0),
+        Row.new(%q(:$a), nil, 0),
+        Row.new(%q(:def), nil, 0),
+        Row.new(%q(:`), nil, 0),
+      ]
+
+      lines = []
+      input_with_correct_indents.each do |row|
+        lines << row.content
+        assert_indenting(lines, row.current_line_spaces, false)
+        assert_indenting(lines, row.new_line_spaces, true)
+      end
+    end
+
     def test_endless_range_at_end_of_line
       if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6.0')
         pend 'Endless range is available in 2.6.0 or later'
-- 
cgit v1.1


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

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