From 926857eb1e124c62ef9cee52bb6c23c83e268ac6 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 19 Aug 2023 14:03:35 -0400 Subject: [PATCH] [ruby/yarp] fix: support newline-terminated regular expressions Previously, parsing a snippet like this: %r\nfoo\n would result in tracking the second newline twice, resulting in a failed runtime assertion. Fixing that issue reveals another bug, which is that the _first_ newline was not being tracked at all. So we introduce a call to yp_newline_list right when we construct the REGEXP_BEGIN token. https://github.com/ruby/yarp/commit/0d5d759091 --- test/yarp/fixtures/newline-terminated-things.txt | 3 +++ test/yarp/snapshots/newline-terminated-things.txt | 7 +++++++ yarp/yarp.c | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/test/yarp/fixtures/newline-terminated-things.txt b/test/yarp/fixtures/newline-terminated-things.txt index 3faf45ab4a..ba07c085b0 100644 --- a/test/yarp/fixtures/newline-terminated-things.txt +++ b/test/yarp/fixtures/newline-terminated-things.txt @@ -1,3 +1,4 @@ +<<<<<<< HEAD:test/yarp/fixtures/newline-terminated-things.txt # note that %i, %I, %w, and %W do not support newline termination in CRuby % @@ -9,5 +10,7 @@ foo %Q foo +======= +>>>>>>> 0d5d759091 (fix: support newline-terminated regular expressions):test/fixtures/newline-terminated-things.txt %r foo diff --git a/test/yarp/snapshots/newline-terminated-things.txt b/test/yarp/snapshots/newline-terminated-things.txt index 946eb44a36..d01bd6a65a 100644 --- a/test/yarp/snapshots/newline-terminated-things.txt +++ b/test/yarp/snapshots/newline-terminated-things.txt @@ -1,3 +1,4 @@ +<<<<<<< HEAD:test/yarp/snapshots/newline-terminated-things.txt ProgramNode(76...106)( [], StatementsNode(76...106)( @@ -11,5 +12,11 @@ ProgramNode(76...106)( "foo", 0 )] +======= +ProgramNode(0...7)( + [], + StatementsNode(0...7)( + [RegularExpressionNode(0...7)((0...3), (3...6), (6...7), "foo", 0)] +>>>>>>> 0d5d759091 (fix: support newline-terminated regular expressions):test/snapshots/newline-terminated-things.txt ) ) diff --git a/yarp/yarp.c b/yarp/yarp.c index d521b7ead9..c425c53c1c 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -6369,7 +6369,13 @@ parser_lex(yp_parser_t *parser) { if (parser->current.end < parser->end) { lex_mode_push_regexp(parser, lex_mode_incrementor(*parser->current.end), lex_mode_terminator(*parser->current.end)); +<<<<<<< HEAD:yarp/yarp.c yp_newline_list_check_append(&parser->newline_list, parser->current.end); +======= + if (parser->current.end == '\n') { + yp_newline_list_append(&parser->newline_list, parser->current.end); + } +>>>>>>> 0d5d759091 (fix: support newline-terminated regular expressions):src/yarp.c parser->current.end++; }