Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Problem with Parse::RecDescent and subrule arguments

by jryan (Vicar)
on Aug 26, 2004 at 00:30 UTC ( [id://385873]=note: print w/replies, xml ) Need Help??


in reply to Problem with Parse::RecDescent and subrule arguments

This one had me stumpted. subrule(s /,/) is just a macro for <leftop: subrule /,/ subrule>, and so subrule(s? /,/) is just a macro for <leftop: subrule /,/ subrule>(?). However, internally, I think that leftop goes through another level, and so @arg must get overwritten. (that's just a guess as to what is happening, so don't take it as fact.) Anyways, whatever P::RD is doing internally, I would classify it as a bug.

However, just telling you that its a bug isn't really helping you, so here is a workaround:

my $parser = new Parse::RecDescent (q[ functiondefine: /function/i name "(" parameters[$item[1]](?) ")" " +{" name: /[A-Za-z][a-zA-Z0-9_]*/ parameters: parameter[$arg[0]] ',' parameters[$arg[0]] { [@ite +m[1,3]] } | parameter[$arg[0]] { [$item[1]] } parameter: name /as/i variabletype { [@item[1..$#item]] } variabletype: /variant|array|keyarray/i ]);

This is much more inefficent then using <leftop:> would be, but at least it works (at least as far as I've tested it.) I also collapsed your variabletype rule into a single regex, which will be much more efficient.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found