Skip to content

Commit

Permalink
Support symbol with backtick
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Sep 8, 2021
1 parent 16d3e59 commit 0aa2425
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/irb/ruby-lex.rb
Expand Up @@ -708,17 +708,24 @@ def check_string_literal(tokens)
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]
when :on_regexp_beg
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
Expand All @@ -729,9 +736,6 @@ def check_string_literal(tokens)
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
Expand Down
20 changes: 20 additions & 0 deletions test/irb/test_ruby_lex.rb
Expand Up @@ -136,6 +136,26 @@ def test_a_closed_brace_and_not_closed_brace_in_a_line
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'
Expand Down

0 comments on commit 0aa2425

Please sign in to comment.