Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Prism::Translation::RubyParser::Compiler#visit_interpolated_parts
visit_interpolated_parts(parts)
lib/prism/translation/ruby_parser.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/prism/translation/ruby_parser.rb, line 882
def visit_interpolated_parts(parts)
visited = []
parts.each do |part|
result = visit(part)
if result[0] == :evstr && result[1]
if result[1][0] == :str
visited << result[1]
elsif result[1][0] == :dstr
visited.concat(result[1][1..-1])
else
visited << result
end
visited << :space
elsif result[0] == :dstr
if !visited.empty? && part.parts[0].is_a?(StringNode)
# If we are in the middle of an implicitly concatenated string,
# we should not have a bare string as the first part. In this
# case we need to visit just that first part and then we can
# push the rest of the parts onto the visited array.
result[1] = visit(part.parts[0])
end
visited.concat(result[1..-1])
else
visited << result
end
end
state = :beginning #: :beginning | :string_content | :interpolated_content
results = []
visited.each_with_index do |result, index|
case state
when :beginning
if result.is_a?(String)
results << result
state = :string_content
elsif result.is_a?(Array) && result[0] == :str
results << result[1]
state = :string_content
else
results << ""
results << result
state = :interpolated_content
end
when :string_content
if result == :space
# continue
elsif result.is_a?(String)
results[0] << result
elsif result.is_a?(Array) && result[0] == :str
results[0] << result[1]
else
results << result
state = :interpolated_content
end
when :interpolated_content
if result == :space
# continue
elsif visited[index - 1] != :space && result.is_a?(Array) && result[0] == :str && results[-1][0] == :str && (results[-1].line_max == result.line)
results[-1][1] << result[1]
results[-1].line_max = result.line_max
else
results << result
end
end
end
results
end
Visit the interpolated content of the string-like node.