Skip to content

Commit

Permalink
Merge pull request #285 from aycabta/support-symbol-with-backtick
Browse files Browse the repository at this point in the history
Support symbol with backtick
  • Loading branch information
aycabta authored Sep 9, 2021
2 parents 16d3e59 + 4d32f0e commit c98d1ea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/irb/ruby-lex.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
17 changes: 17 additions & 0 deletions test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ class A def b; self; end; def c; true; end; end;
EOC
end

def test_symbol_with_backtick
write_irbrc <<~'LINES'
puts 'start IRB'
LINES
start_terminal(40, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
write(<<~EOC)
:`
EOC
close
assert_screen(<<~EOC)
start IRB
irb(main):001:0> :`
=> :`
irb(main):002:0>
EOC
end

private def write_irbrc(content)
File.open(@irbrc_file, 'w') do |f|
f.write content
Expand Down

0 comments on commit c98d1ea

Please sign in to comment.