|Just another Perl shrine|
Parse::RecDescent grammar that winds its way all the way back to startby sundialsvc4 (Monsignor)
|on Sep 23, 2010 at 15:11 UTC||Need Help??|
sundialsvc4 has asked for the
wisdom of the Perl Monks concerning the following question:
I am dealing with trying to write a Parse::RecDescent grammar for a file syntax that basically looks like this:
Which I handle with:
This start-rule has an alternative: <error: No \$JOBS statement
The definition for job_definition then looks like: job_name <commit> job_options(?) , the trouble being that in this syntax there is no reserved-word that separates one job-definition from the next.
The problem that I seem to be having is this: when there is any sort of syntax-error in any of the job-definitions, I see the parser merrily unwinding its way all the way back to start. The failed parse always produces a “NO $JOBS STATEMENT” error, as the starting-rule fails.
So, for example, let’s say that I’ve got a job-file with 156 job definitions in it... and there’s a syntax-error on number 132. Boing-g-g-g-g-g!! The grammar winds its way all the way back to start, having backtracked all the way to the point where it imagines that perhaps this could be an altogether different kind of file.
What I want, I think, is for the parser, having recognized one occurrence of job_statement, to at that point <commit> to it.
Here's some relevant code ... EDIT: Greatly Reduced!