Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Parse::RecDescent grammar definition

by jethro (Monsignor)
on Mar 21, 2011 at 12:09 UTC ( [id://894486]=note: print w/replies, xml ) Need Help??


in reply to Parse::RecDescent grammar definition

Return value (if you don't specify anything through $return) is the value of the last successfully matched items. The information can be found in the documentation in section 'Subrules':

The value associated with a subrule is the value associated with its $return variable (see "Actions" below), or with the last successfully matched item in the subrule match.

The second problem is that your print statement only belongs to the second rule, i.e. if Pre is matched, nothing is done at all. You might check the return value of your call to $p2->Format to see if a production was parsed successfully

  • Comment on Re: Parse::RecDescent grammar definition

Replies are listed 'Best First'.
Re^2: Parse::RecDescent grammar definition
by citromatik (Curate) on Mar 21, 2011 at 17:15 UTC
    The second problem is that your print statement only belongs to the second rule, i.e. if Pre is matched, nothing is done at all.

    Wow, there is something I am not getting here. I would expect %item to have what matches in the rule, so if the rule is "Pre | Post", %item would have either the "Pre" or the "Post" matching part.

    Obviously I am getting all this wrong

    citromatik

      You are right, %item has either the Pre or Post matching part. But only in one case does it print anything!

      Entry : Pre | Post { use Data::Dumper; print Dumper \%item;} # is equivalent to Entry : Pre Entry : Post { use Data::Dumper; print Dumper \%item; } # is equivalent to Entry : Post { use Data::Dumper; print Dumper \%item; } Entry : Pre # is NOT equivalent to Entry : Pre { use Data::Dumper; print Dumper \%item; } Entry : Post { use Data::Dumper; print Dumper \%item; }

      And the last example is what you want

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://894486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found