Skip to content

Commit

Permalink
Implement string concat for ripper translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Mar 6, 2024
1 parent 240bb08 commit 6019342
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 9 additions & 1 deletion lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1696,11 +1696,19 @@ def visit_interpolated_regular_expression_node(node)
# "foo #{bar}"
# ^^^^^^^^^^^^
def visit_interpolated_string_node(node)
if node.opening.start_with?("<<~")
if node.opening&.start_with?("<<~")
heredoc = visit_string_heredoc_node(node.parts)

bounds(node.location)
on_string_literal(heredoc)
elsif !node.heredoc? && node.parts.length > 1 && node.parts.any? { |part| (part.is_a?(StringNode) || part.is_a?(InterpolatedStringNode)) && !part.opening_loc.nil? }
first, *rest = node.parts
rest.inject(visit(first)) do |content, part|
concat = visit(part)

bounds(part.location)
on_string_concat(content, concat)
end
else
bounds(node.parts.first.location)
parts =
Expand Down
5 changes: 0 additions & 5 deletions test/prism/ripper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,11 @@ class RipperTest < TestCase
seattlerb/lambda_do_vs_brace.txt
seattlerb/parse_line_dstr_escaped_newline.txt
seattlerb/parse_line_dstr_soft_newline.txt
seattlerb/parse_line_evstr_after_break.txt
seattlerb/parse_pattern_051.txt
seattlerb/parse_pattern_058.txt
seattlerb/stabby_block_iter_call.txt
seattlerb/stabby_block_iter_call_no_target_with_arg.txt
seattlerb/str_lit_concat_bad_encodings.txt
spanning_heredoc.txt
strings.txt
tilde_heredocs.txt
unparser/corpus/literal/assignment.txt
unparser/corpus/literal/block.txt
Expand Down Expand Up @@ -96,10 +93,8 @@ class RipperTest < TestCase
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
whitequark/parser_slash_slash_n_escaping_in_literals.txt
whitequark/ruby_bug_11107.txt
whitequark/ruby_bug_11990.txt
whitequark/send_block_chain_cmd.txt
whitequark/slash_newline_in_heredocs.txt
whitequark/string_concat.txt
]

relatives.each do |relative|
Expand Down

0 comments on commit 6019342

Please sign in to comment.