3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 19:22:40 +01:00

CGrammar: Return output instead of printing; improve error-handling of misparsed code

This commit is contained in:
Pragmatic Software 2014-06-22 06:08:01 +00:00
parent e9b3d7e255
commit d97f8b2fd6
3 changed files with 13 additions and 5 deletions

View File

@ -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",
};

View File

@ -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

View File

@ -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";