Skip to content

Commit 9e4ed57

Browse files
committed
ParseXS: refactor: remove $ExtUtils::ParseXS::END
(This commit is part of a series which will extend the AST parse tree from just representing individual XSUBs to representing the whole XS file.) The parser, when parsing an XSUB (but not any other parts of an XS file), pushes a special token onto the end of the list of lines in @{$pxs->{line}} which make up the current paragraph. This token, $ExtUtils::ParseXS::END = "!End!\n\n"; (along with a trailing ':') is designed to look like an impossible keyword which can't actually appear in the source code (due to the multiple newlines). It looks like it was originally added in perl5.002 to make the parsing code easier, but I don't really understand why. It just makes the parser harder to understand. So this commit removes it, and just relies on @{$pxs->{line}} being zero to detect the end of the paragraph. This change doesn't alter the C code generated from any of the XS files bundled with perl.
1 parent 0bed57b commit 9e4ed57

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ our $AUTHOR_WARNINGS;
103103
$AUTHOR_WARNINGS = ($ENV{AUTHOR_WARNINGS} || 0)
104104
unless defined $AUTHOR_WARNINGS;
105105

106-
# "impossible" keyword (multiple newline)
107-
our $END = "!End!\n\n";
108106
# Match an XS Keyword
109-
our $BLOCK_regexp = '\s*(' . $ExtUtils::ParseXS::Constants::XSKeywordsAlternation . "|$END)\\s*:";
107+
our $BLOCK_regexp = '\s*(' . $ExtUtils::ParseXS::Constants::XSKeywordsAlternation . ")\\s*:";
110108

111109

112110
# All the valid fields of an ExtUtils::ParseXS hash object. The 'use

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,12 +1210,8 @@ sub parse {
12101210

12111211

12121212

1213-
# should just be a fake END token left
1214-
die "Internal error: bad END token\n"
1215-
unless $pxs->{line}
1216-
&& @{$pxs->{line}} == 1
1217-
&& $pxs->{line}[0] eq "$ExtUtils::ParseXS::END:";
1218-
pop @{$pxs->{line}};
1213+
die "Internal error: unexpectedly not at EOF\n"
1214+
if @{$pxs->{line}};
12191215

12201216
$pxs->{seen_an_XSUB} = 1; # encountered at least one XSUB
12211217
} # END 'PARAGRAPH' 'while' loop
@@ -1786,13 +1782,6 @@ sub parse {
17861782
or return;
17871783
push @{$self->{kids}}, $decl;
17881784

1789-
# Append a fake EOF-keyword line. This makes it easy to do "all lines
1790-
# until the next keyword" style loops, since the fake END line (which
1791-
# includes a \n so it can't appear in the wild) is also matched as a
1792-
# keyword.
1793-
push(@{ $pxs->{line} }, "$ExtUtils::ParseXS::END:");
1794-
push(@{ $pxs->{line_no} }, $pxs->{line_no}->[-1]);
1795-
17961785
$_ = '';
17971786

17981787
# Check all the @{ $pxs->{line}} lines for balance: all the
@@ -1810,7 +1799,7 @@ sub parse {
18101799
my $case_had_cond; # the previous CASE had a condition
18111800

18121801
# Repeatedly look for CASE or XSUB body.
1813-
while (@{ $pxs->{line} }) {
1802+
while (1) {
18141803
# Parse a CASE statement if present.
18151804
my ($case) =
18161805
$self->parse_keywords(
@@ -1830,10 +1819,10 @@ sub parse {
18301819
else {
18311820
$seen_bare_xbody = 1;
18321821
if ($num++) {
1833-
my $l = $pxs->{line}[0];
18341822
# After the first CASE+body, we should only encounter
18351823
# further CASE+bodies or end-of-paragraph
1836-
last if $l eq "$ExtUtils::ParseXS::END:";
1824+
last unless @{$pxs->{line}};
1825+
my $l = $pxs->{line}[0];
18371826
$pxs->death(
18381827
$l =~ /^$ExtUtils::ParseXS::BLOCK_regexp/o
18391828
? "Error: misplaced '$1:'"
@@ -5701,8 +5690,7 @@ sub parse {
57015690

57025691
$self->SUPER::parse($pxs); # set file/line_no/lines
57035692
$xsub->{seen_PPCODE} = 1;
5704-
# The only thing left should be the special "!End!\n\n" token.
5705-
$pxs->death("Error: PPCODE must be the last thing") if @{$pxs->{line}} > 1;
5693+
$pxs->death("Error: PPCODE must be the last thing") if @{$pxs->{line}};
57065694
1;
57075695
}
57085696

0 commit comments

Comments
 (0)