Skip to content

Commit

Permalink
Merge pull request #86 from ddiss/show_spec_line_number_on_ifs_error
Browse files Browse the repository at this point in the history
spec_query: print line numbers on %if/%else/%endif error
  • Loading branch information
DimStar77 committed Sep 17, 2021
2 parents 85ed9c9 + 3dfa6c2 commit 5410db5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions helpers/spec_query
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sub prepare_spec {
my %seen;
my $dtags;
my @ifs;
while (<F>) {
for (my $line = 0; <F>; $line++) {
# only process if conditionals in non line continuation contexts
if (/^\s*%(?:define|global).*\\$/) {
push @$spec, $_;
Expand All @@ -39,20 +39,20 @@ sub prepare_spec {
}

if (/^\s*%if\s+.*%\{?name/ && $keep_name_conditionals) {
unshift @ifs, $st_ifname;
unshift @ifs, { $st_ifname => $line };
} elsif (/^\s*%if/) {
unshift @ifs, $st_if;
unshift @ifs, { $st_if => $line };
next;
} elsif (/^\s*%else/) {
die("got %else without %if\n") unless @ifs;
if ($ifs[0] == $st_ifname) {
die($line . ": %else without %if\n") unless @ifs;
if (exists $ifs[0]{$st_ifname}) {
push @$spec, "%endif";
$ifs[0] = $st_if;
$ifs[0] = { $st_if => $line };
}
next;
} elsif (/^\s*%endif/) {
die("got %endif without %if\n") unless @ifs;
push @$spec, "%endif" if $ifs[0] == $st_ifname;
die($line . ": %endif without %if\n") unless @ifs;
push @$spec, "%endif" if (exists $ifs[0]{$st_ifname});
shift @ifs;
next;
}
Expand All @@ -70,7 +70,11 @@ sub prepare_spec {
}
push @$spec, $_;
}
die("got %if without %endif\n") if @ifs;
if (@ifs and exists $ifs[0]{$st_if}) {
die($ifs[0]{$st_if} . ": %if without %endif\n");
} elsif (@ifs) {
die($ifs[0]{$st_ifname} . ": %if name without %endif\n");
}
close(F) || die("close: $!\n");
my @amb = sort(keys(%$dtags));
die('Ambiguous tags: ' . join(', ', @amb) . "\n") if $unique_sources && @amb;
Expand Down

0 comments on commit 5410db5

Please sign in to comment.