summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-09-08 22:19:52 +0900
committergit <svn-admin@ruby-lang.org>2021-09-10 04:59:17 +0900
commitf085a6fb6953a23e555cae7ffe4274927c6b0961 (patch)
treebd8bf3be2bad2655f8598020548a36a13f0e93f9
parent419e6ed464b2abcc18b60d1bcbd183fe9dfb99c2 (diff)
[ruby/irb] Support symbol with backtick
https://github.com/ruby/irb/commit/0aa2425883
-rw-r--r--lib/irb/ruby-lex.rb18
-rw-r--r--test/irb/test_ruby_lex.rb20
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index f744f36155..e281169788 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -708,6 +708,9 @@ class RubyLex
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
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
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 d31d38dc99..e255720e25 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -136,6 +136,26 @@ module TestIRB
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'