The Parse::RecDescent documentation states
If a quote-delimited string or a Perl regex appears in a
production, the parser attempts to match that string or
pattern at that point in the text.
I thought I had found a bug in this: when I tried to use
While trying to post about the issue here, I decided to develop a minimalist program to demonstrate the problem
use Parse::RecDescent;
my $grammar = <<"EOF";
digit :/\d/
EOF
my $parser = Parse::RecDescent->new($grammar);
my $r;
$r = $parser->digit("7");
print "[$r]\n";
Turns out the problem is those double-quotation marks around my EOF. That causes perl in constructing the string to try to interpret the \d, which of course does not work! The warning I was getting was not P::RD, but perl warning me I'd made a string it couldn't completely handle (unrecognized escape sequence). Then of course the parser failed, because it had an empty rule in it.
The moral of the story is when you can't get someone to stand over your shoulder and expose how you're coding like an idiot, post it to use.perl instead so you can spot it yourself in the process.
Parse::RecDescent regexes 0 Comments More | Login | Reply /