[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
This commit is contained in:
Mike Dalessio 2023-08-19 14:03:35 -04:00 committed by Jemma Issroff
parent e63bac3128
commit 926857eb1e
3 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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
)
)

View File

@ -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++;
}