ParseXS: fix handling of empty C_ARGS etc

GH#23407

My recent refactoring work on ParseXS made the parser go into an
infinite loop on multiline_merged nodes such as C_ARGS when there was no
text, e.g.

    void
    foo(int  a)
        C_ARGS:
This commit is contained in:
David Mitchell 2025-07-07 09:33:17 +01:00
parent b0823b6ac8
commit d2d154ba92
2 changed files with 11 additions and 1 deletions

View File

@ -3648,7 +3648,7 @@ sub parse {
$self->SUPER::parse($pxs); # set file/line_no, read lines
my @lines = @{$self->{lines}};
shift @lines while $lines[0] !~ /\S/;
shift @lines while @lines && $lines[0] !~ /\S/;
# XXX ParseXS originally didn't include a trailing \n,
# so we carry on doing the same.
$self->{text} = join "\n", @lines;

View File

@ -1656,6 +1656,16 @@ EOF
[ 0, 0, qr/\Qfoo(a, b , bar, c? c : "boo!")/, "" ],
],
[
"autocall args empty C_ARGS",
[ Q(<<'EOF') ],
|void
|foo(int a)
| C_ARGS:
EOF
[ 0, 0, qr/\Qfoo()/, "" ],
],
[
# Whether this is sensible or not is another matter.
# For now, just check that it works as-is.