in reply to Parse::RecDescent grammar and Parenthesis

Yes, as others have pointed out, it's the return statements that are the problem.

Actions are transformed into do blocks within the subroutine that implements each rule. That means that if an action executes a return, the entire surrounding subroutine (i.e. the entire rule) returns. Immediately.

In that case, subsequent items in the current production are not considered, nor are subsequent productions in the current rule. So typically, you get a "match", but not of the entire input. Or you get a "failed-to-match" on the next rule, even though the production that was supposed to match the previous input seems to succeed.

Hmmmmm. This is becoming a frequently encountered trap as more and more people are using the module. That usually indicates that the original design is flawed (because the module isn't DWIMing). I suspect that a near-future release may translate:

{ action() }
not to:
do { action() }
but to:
{ action() }->()
so as to make the behaviour of embedded returns conform to people's expection.

Replies are listed 'Best First'.
Re: Re: Parse::RecDescent grammar and Parenthesis
by Masem (Monsignor) on Dec 18, 2001 at 07:26 UTC
    I think, as crazyinsomniac pointed out to me in privmsg, that while the POD and what I have here as a tutorial and some other sources all use $return, this tutorial at perl.com uses the return() form, which for their case, works, but doesn't work in the general case. Given that I bet a lot of people were introduced to this module via perl.com, I suspect this is where you are seeing this error pop up. CI says he was going to fire a message off to the author, Jeffory Goff, and see if he can't get it updated.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important