mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
CGrammar: Return output instead of printing; improve error-handling of misparsed code
This commit is contained in:
parent
e9b3d7e255
commit
d97f8b2fd6
@ -13,7 +13,7 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 667,
|
||||
BUILD_REVISION => 668,
|
||||
BUILD_DATE => "2014-06-21",
|
||||
};
|
||||
|
||||
|
@ -17,9 +17,10 @@ startrule:
|
||||
my $output = $item[-1];
|
||||
$output =~ s/\^L(\s*.?)/\L$1/g; # lowercase specified characters
|
||||
$output =~ s/\^U(\s*.?)/\U$1/g; # uppercase specified characters
|
||||
print $output;
|
||||
push @$return, $output;
|
||||
}
|
||||
startrule(?)
|
||||
{ push @$return, $item[-1]; }
|
||||
|
||||
translation_unit:
|
||||
comment
|
||||
|
@ -61,11 +61,18 @@ foreach my $arg (@ARGV) {
|
||||
undef $::RD_TRACE;
|
||||
}
|
||||
|
||||
defined $parser->startrule(\$text) or die "Bad text!\n$text\n";
|
||||
my $result = $parser->startrule(\$text) or die "Bad text!\n$text\n";
|
||||
|
||||
$text =~ s/^\s+//g;
|
||||
$text =~ s/\s+$//g;
|
||||
|
||||
if(length $text) {
|
||||
die "Bad parse: $text";
|
||||
} else {
|
||||
print join('', flatten($result));
|
||||
}
|
||||
}
|
||||
|
||||
$text =~ s/\s+//g;
|
||||
print "\n[$text]\n" if length $text;
|
||||
|
||||
sub precompile_grammar {
|
||||
print STDERR "Precompiling grammar...\n";
|
||||
|
Loading…
Reference in New Issue
Block a user