in reply to Parse::RecDescent grammar that winds its way all the way back to start

Okay, I think that I have come up with a workable solution.   (Given that the only parser-tool that I have to work with, in this case, is this one ...)

Well, the first thing that I did, as you can see, is to shrink the size of the grammar-example in the original post to “just an example.”   (Sorry about that.)

Then, I came up with a production like this:

job_list : job_statement job_list | #NOTHING

The rule does recurse.   When the “nothing” case is encountered (which simply means that “whatever we are looking at now, whatever it is, is not a job_statement”) the result of the production is a string consisting of the name of the nonterminal (“job_list”).   The action code (not shown) ignores that.

Replies are listed 'Best First'.
Re^2: Parse::RecDescent grammar that winds its way all the way back to start
by ikegami (Patriarch) on Sep 23, 2010 at 23:02 UTC

    Well, the first thing that I did, as you can see, is to shrink the size of the grammar-example in the original post to “just an example.”

    You still not clear what you want out of it.

    If you simply don't want it to fail, use a production that always matches instead of using <error>.

    Then, I came up with a production like this:

    job_list : job_statement job_list | #NOTHING

    will match the same as

    job_list : job_statement(s?)