/usr/share/doc/libparse-recdescent-perl/examples/demo_errors.pl is in libparse-recdescent-perl 1.965001+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | use v5.10;
use warnings;
# THE ONLY TRUE MISTAKES ARE THE ONES YOU NEVER MAKE
#BEGIN {
# close STDERR and open STDERR, '>./STDERR' or die $!;
#}
use Parse::RecDescent;
$grammar =
q{
Para: Sentence(s) /\Z/
# Can also intercept the error messages like so: ##
| { use Data::Dumper 'Dumper';
print "$_->[0]\n" for @{$thisparser->{errors}};
exit;
}
Sentence: Noun Verb
| Verb Noun
| <error>
Noun: Fish
| Cat
| 'dog'
Verb: 'runs'
Fish: 'fish'
| <error:Expected a fish! But didn't get one>
Cat: 'cat'
| <error:I wanna cat!>
};
$parse = new Parse::RecDescent ($grammar);
while (<DATA>)
{
chomp;
print "$_...\n";
$parse->Para($_);
}
__DATA__
rat runs
dog runs
cat purrs
cat runs
mouse squeaks
|