Understanding resynchronization
[email protected] (Doug Bering)
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
I'm using Parse::RecDescent on a language (BSDL) that has statements
terminating with a semicolon. Everything works fine as long as I have
correct input. My problem is in understanding error recovery and
resychronization.
If parsing fails on a statement, I'd like to report an error, skip
that statement, and continue with the rest of the source; hoping to pick
up multiple errors in one run.
Unfortunately, parsing seems to quit with the first error (the text
remaining goes back to the full input text and the process stops).
Attached is a simple test case that I've cobbled together that
demonstrates the problem. Any ideas?
#!/usr/local/bin/perl
use strict;
use English;
use Parse::RecDescent;
$::RD_HINT = 1; # Turn on hints
my $grammar = join( '', <DATA> );
my $parser = new Parse::RecDescent( $grammar );
my $text = <<eof;
a b c d e;
a b b d e;
a b c d e;
a a b b e;
eof
$::RD_TRACE = 1;
$parser->_________( $text );
__DATA__
_________:
Line(s)
Eofile | <error>
Line: Line1
| Line2
| <resync: [^;]*;> <reject>
Line1:
a_rule b_rule c_rule d_rule e_rule ';'
{ print "#################### Passed First statement\n" }
Line2:
a_rule a_rule b_rule b_rule e_rule ';'
{ print "#################### Passed second statement\n" }
Eofile:
m!^\Z!
{ print "EOF at $thisline\n"; }
#-----------------------------------------------------------------------
a_rule: m!a!i
b_rule: m!b!i
c_rule: m!c!i
d_rule: m!d!i
e_rule: m!e!i