Skip to content

Commit e93d277

Browse files
committed
ParseXS: refactor: rationalise parse-fail action
Now that the XS parser builds a parse tree (AST), it spends most of its time doing recursive-descent $some_node_object->parse() calls. There is a common idiom within the current code along the lines of $some_node_object->parse() or return; This makes a parse failure in a node propagate its way back up the call chain. Note that many parse failures don't immediately croak; they call blurt() which only warns, but also increments the error count; parsing can continue. During my big refactoring I haven't been entirely consistent here; this commit adds a bunch of 'or return's that I missed. It also does a few 'or next's at higher levels, to get behaviour along the lines of: "this XSUB had a syntax error, but continue trying to parse other XSUBs, and only error out at the end." This is all a bit going on gut feelings; in the final analysis it doesn't matter too much how much more parsing gets done before xsubpp finally croaks out.
1 parent 64d7e86 commit e93d277

File tree

1 file changed

+13
-7
lines changed
  • dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ sub parse {
552552

553553
my $cpp_scope = ExtUtils::ParseXS::Node::cpp_scope->new({type => 'main'});
554554
$self->{cpp_scope} = $cpp_scope;
555-
$cpp_scope->parse($pxs);
555+
$cpp_scope->parse($pxs)
556+
or return;
556557
push @{$self->{kids}}, $cpp_scope;
557558

558559
# Now at EOF: all paragraphs (and thus XSUBs) have now been read in
@@ -1092,7 +1093,8 @@ sub parse {
10921093

10931094
if ($pxs->{line}[0] =~ /^#/) {
10941095
my $node = ExtUtils::ParseXS::Node::global_cpp_line->new();
1095-
$node->parse($pxs);
1096+
$node->parse($pxs)
1097+
or next;
10961098
push @{$self->{kids}}, $node;
10971099

10981100
next unless $node->{is_cond};
@@ -1121,7 +1123,7 @@ sub parse {
11211123
my $scope = ExtUtils::ParseXS::Node::cpp_scope->new(
11221124
{type => 'if'});
11231125
$scope->parse($pxs)
1124-
or return 1;
1126+
or next;
11251127

11261128
# Sub-parsing of that branch should have terminated
11271129
# at an elif/endif line rather than falling off the
@@ -1910,7 +1912,8 @@ sub parse {
19101912
# Parse the XSUB's body
19111913

19121914
my $xbody = ExtUtils::ParseXS::Node::xbody->new();
1913-
$xbody->parse($pxs, $self);
1915+
$xbody->parse($pxs, $self)
1916+
or return;
19141917

19151918
if (defined $case) {
19161919
# make the xbody a child of the CASE
@@ -2306,7 +2309,8 @@ sub parse {
23062309

23072310
my $params = $self->{params} = ExtUtils::ParseXS::Node::Params->new();
23082311

2309-
$params->parse($pxs, $xsub, $params_text);
2312+
$params->parse($pxs, $xsub, $params_text)
2313+
or return;
23102314
$self->{params} = $params;
23112315
push @{$self->{kids}}, $params;
23122316

@@ -4351,7 +4355,8 @@ sub parse {
43514355

43524356
my $autocall = ExtUtils::ParseXS::Node::autocall->new();
43534357
# mainly a NOOP, but sets line number etc and flags that autocall seen
4354-
$autocall->parse($pxs, $xsub, $xbody);
4358+
$autocall->parse($pxs, $xsub, $xbody)
4359+
or return;
43554360
push @{$self->{kids}}, $autocall;
43564361

43574362
1;
@@ -5048,7 +5053,8 @@ sub parse {
50485053
type => 'include',
50495054
is_cmd => $self->{is_cmd},
50505055
});
5051-
$cpp_scope->parse($pxs);
5056+
$cpp_scope->parse($pxs)
5057+
or return;
50525058
push @{$self->{kids}}, $cpp_scope;
50535059

50545060
--$pxs->{IncludedFiles}->{$pxs->{in_filename}}

0 commit comments

Comments
 (0)