[ruby/yarp] fix: %W list spanning a heredoc

Primarily this fix is to accept a string node and concatenate it onto
an interpolated string.

https://github.com/ruby/yarp/commit/6df729fe72
This commit is contained in:
Mike Dalessio 2023-08-27 16:34:53 -04:00 committed by git
parent 77e971b6ec
commit 74812df496
3 changed files with 49 additions and 2 deletions

View File

@ -29,3 +29,10 @@ pp <<-A, %w[j\
i
A
j]
# ripper can't parse this successfully, though ruby runs it correctly
# TODO: yarp does not include the "\n" in "l\nl" in the AST like ruby does
pp <<-A, %W[l\
k
A
l]

View File

@ -1,6 +1,6 @@
ProgramNode(164...541)(
ProgramNode(164...709)(
[],
StatementsNode(164...541)(
StatementsNode(164...709)(
[CallNode(164...192)(
nil,
nil,
@ -133,6 +133,33 @@ ProgramNode(164...541)(
nil,
0,
"pp"
),
CallNode(688...709)(
nil,
nil,
(688...690),
nil,
ArgumentsNode(691...709)(
[InterpolatedStringNode(691...695)(
(691...695),
[StringNode(703...705)(nil, (703...705), nil, "k\n")],
(705...707)
),
ArrayNode(697...709)(
[InterpolatedStringNode(700...708)(
nil,
[StringNode(700...703)(nil, (700...703), nil, "l"),
StringNode(707...708)(nil, (707...708), nil, "l")],
nil
)],
(697...700),
(708...709)
)]
),
nil,
nil,
0,
"pp"
)]
)
)

View File

@ -12160,6 +12160,19 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
// to the list of child nodes.
yp_node_t *part = parse_string_part(parser);
yp_interpolated_string_node_append((yp_interpolated_string_node_t *) current, part);
} else if (YP_NODE_TYPE_P(current, YP_NODE_STRING_NODE)) {
// If we hit string content and the current node is a string node,
// then we need to convert the current node into an interpolated
// string and add the string content to the list of child nodes.
yp_token_t opening = not_provided(parser);
yp_token_t closing = not_provided(parser);
yp_interpolated_string_node_t *interpolated =
yp_interpolated_string_node_create(parser, &opening, NULL, &closing);
yp_interpolated_string_node_append(interpolated, current);
yp_node_t *part = parse_string_part(parser);
yp_interpolated_string_node_append(interpolated, part);
current = (yp_node_t *) interpolated;
} else {
assert(false && "unreachable");
}