diff --git a/test/yarp/fixtures/spanning_heredoc.txt b/test/yarp/fixtures/spanning_heredoc.txt index 1b17edac5d..a81731a181 100644 --- a/test/yarp/fixtures/spanning_heredoc.txt +++ b/test/yarp/fixtures/spanning_heredoc.txt @@ -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] diff --git a/test/yarp/snapshots/spanning_heredoc.txt b/test/yarp/snapshots/spanning_heredoc.txt index f948e1e9d3..a0f58a97bf 100644 --- a/test/yarp/snapshots/spanning_heredoc.txt +++ b/test/yarp/snapshots/spanning_heredoc.txt @@ -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" )] ) ) diff --git a/yarp/yarp.c b/yarp/yarp.c index a4b1c9be3c..7306d9e8e5 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -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"); }