[ruby/prism] Fix xstring heredoc parser translator

https://github.com/ruby/prism/commit/4e0f703975
This commit is contained in:
Kevin Newton 2024-02-26 09:35:52 -05:00 коммит произвёл git
Родитель 99d0f687fc
Коммит 1ce3d9acbf
2 изменённых файлов: 30 добавлений и 6 удалений

Просмотреть файл

@ -49,10 +49,34 @@ module Prism
class StringNode < Node
include HeredocQuery
# Occasionally it's helpful to treat a string as if it were interpolated so
# that there's a consistent interface for working with strings.
def to_interpolated
InterpolatedStringNode.new(
source,
opening_loc,
[copy(opening_loc: nil, closing_loc: nil, location: content_loc)],
closing_loc,
location
)
end
end
class XStringNode < Node
include HeredocQuery
# Occasionally it's helpful to treat a string as if it were interpolated so
# that there's a consistent interface for working with strings.
def to_interpolated
InterpolatedXStringNode.new(
source,
opening_loc,
[StringNode.new(source, 0, nil, content_loc, nil, unescaped, content_loc)],
closing_loc,
location
)
end
end
private_constant :HeredocQuery

Просмотреть файл

@ -942,7 +942,7 @@ module Prism
# "foo #{bar}"
# ^^^^^^^^^^^^
def visit_interpolated_string_node(node)
if node.opening&.start_with?("<<")
if node.heredoc?
children, closing = visit_heredoc(node)
builder.string_compose(token(node.opening_loc), children, closing)
else
@ -967,7 +967,7 @@ module Prism
# `foo #{bar}`
# ^^^^^^^^^^^^
def visit_interpolated_x_string_node(node)
if node.opening.start_with?("<<")
if node.heredoc?
children, closing = visit_heredoc(node)
builder.xstring_compose(token(node.opening_loc), children, closing)
else
@ -1485,8 +1485,8 @@ module Prism
# "foo"
# ^^^^^
def visit_string_node(node)
if node.opening&.start_with?("<<")
children, closing = visit_heredoc(InterpolatedStringNode.new(node.send(:source), node.opening_loc, [node.copy(opening_loc: nil, closing_loc: nil, location: node.content_loc)], node.closing_loc, node.location))
if node.heredoc?
children, closing = visit_heredoc(node.to_interpolated)
builder.string_compose(token(node.opening_loc), children, closing)
elsif node.opening == "?"
builder.character([node.unescaped, srange(node.location)])
@ -1646,8 +1646,8 @@ module Prism
# `foo`
# ^^^^^
def visit_x_string_node(node)
if node.opening&.start_with?("<<")
children, closing = visit_heredoc(InterpolatedXStringNode.new(node.opening_loc, [StringNode.new(0, nil, node.content_loc, nil, node.unescaped, node.content_loc)], node.closing_loc, node.location))
if node.heredoc?
children, closing = visit_heredoc(node.to_interpolated)
builder.xstring_compose(token(node.opening_loc), children, closing)
else
builder.xstring_compose(