locked_user 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:
$JOBS <job_definition> ... (EOF)
Which I handle with:
startule: /\$JOBS\b/ix <commit> jobfile_joblist EOFILE jobfile_joblist: job_statement(s)
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!
startrule__schedule_file: startrule_1_schedule_file startrule_1_schedule_file: /SCHEDULE\b/ix <commit> schedule_name <com +mit> schedule_optionlist ':' <commit> schedule_joblist EOFILE | <error: no SCHEDULE statement> schedule_optionlist: schedule_option(s?) schedule_joblist: job_statement(s) | <error: Schedule contains no jobs>