From 29c5b851281da753ea0ae204afbd3f9010b466bc Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 27 Aug 2023 16:40:18 -0400 Subject: [PATCH] [ruby/yarp] fix: %i list spanning a heredoc The fix here is similar to what we did in a previous commit for %w, to accept two consecutive string tokens without a separator. https://github.com/ruby/yarp/commit/f869fbdbe5 --- test/yarp/fixtures/spanning_heredoc.txt | 6 ++++++ test/yarp/snapshots/spanning_heredoc.txt | 27 ++++++++++++++++++++++-- yarp/yarp.c | 9 ++------ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/test/yarp/fixtures/spanning_heredoc.txt b/test/yarp/fixtures/spanning_heredoc.txt index a81731a181..c1852e377a 100644 --- a/test/yarp/fixtures/spanning_heredoc.txt +++ b/test/yarp/fixtures/spanning_heredoc.txt @@ -36,3 +36,9 @@ pp <<-A, %W[l\ k A l] + +# ripper can't parse this successfully, though ruby runs it correctly +pp <<-A, %i[n\ +m +A +n] diff --git a/test/yarp/snapshots/spanning_heredoc.txt b/test/yarp/snapshots/spanning_heredoc.txt index a0f58a97bf..3d223e5e4d 100644 --- a/test/yarp/snapshots/spanning_heredoc.txt +++ b/test/yarp/snapshots/spanning_heredoc.txt @@ -1,6 +1,6 @@ -ProgramNode(164...709)( +ProgramNode(164...802)( [], - StatementsNode(164...709)( + StatementsNode(164...802)( [CallNode(164...192)( nil, nil, @@ -160,6 +160,29 @@ ProgramNode(164...709)( nil, 0, "pp" + ), + CallNode(781...802)( + nil, + nil, + (781...783), + nil, + ArgumentsNode(784...802)( + [InterpolatedStringNode(784...788)( + (784...788), + [StringNode(796...798)(nil, (796...798), nil, "m\n")], + (798...800) + ), + ArrayNode(790...802)( + [SymbolNode(793...796)(nil, (793...796), nil, "n\\\n"), + SymbolNode(800...801)(nil, (800...801), nil, "n")], + (790...793), + (801...802) + )] + ), + nil, + nil, + 0, + "pp" )] ) ) diff --git a/yarp/yarp.c b/yarp/yarp.c index 7306d9e8e5..1f707696bb 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -11944,14 +11944,9 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) { yp_array_node_t *array = yp_array_node_create(parser, &parser->previous); while (!match_any_type_p(parser, 2, YP_TOKEN_STRING_END, YP_TOKEN_EOF)) { - if (yp_array_node_size(array) == 0) { - accept(parser, YP_TOKEN_WORDS_SEP); - } else { - expect(parser, YP_TOKEN_WORDS_SEP, "Expected a separator for the symbols in a `%i` list."); - if (match_type_p(parser, YP_TOKEN_STRING_END)) break; - } - + accept(parser, YP_TOKEN_WORDS_SEP); if (match_type_p(parser, YP_TOKEN_STRING_END)) break; + expect(parser, YP_TOKEN_STRING_CONTENT, "Expected a symbol in a `%i` list."); yp_token_t opening = not_provided(parser);