Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[build] warn about stray #?endif in gen-cat.nqp
  • Loading branch information
moritz committed Sep 10, 2014
1 parent e8ab80a commit 2b7e232
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tools/build/gen-cat.nqp
Expand Up @@ -18,22 +18,30 @@ sub MAIN(*@ARGS) {
}
close($fh);
}
my $stderr := nqp::getstderr();
for @ARGS -> $file {
say("# From '$file'\n");
my $fh := open($file, :r);
my $in_cond := 0;
my $in_omit := 0;
my int $in_cond := 0;
my int $in_omit := 0;
my int $line := 1;
while nqp::readlinefh($fh) -> $_ {
if my $x := $_ ~~ / ^ '#?if' \s+ ('!')? \s* (\w+) \s* $ / {
nqp::die("Nested conditionals not supported") if $in_cond;
$in_cond := 1;
$in_omit := $x[0] && $x[1] eq $backend || !$x[0] && $x[1] ne $backend;
} elsif $_ ~~ /^ '#?endif' / {
unless $in_cond {
nqp::sayfh($stderr,
"#?endif without matching #?if in file $file, line $line"
);
}
$in_cond := 0;
$in_omit := 0;
} elsif !$in_omit {
print($_) unless $_ ~~ /^ '# ' \w /;
}
$line++;
}
close($fh);
}
Expand Down

0 comments on commit 2b7e232

Please sign in to comment.