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

I added the line
Parse::RecDescent->Precompile($grammar, "Grammar");
and looked at the source of the parser that was created. @args is simply never set! It's simply inherited down from the parent production as if [ $item[2] ] wasn't there. So I tried to see if it worked with simpler expressions:

# NO WORKS: funcdefine: /function/i name "(" parameter[ $item[2] ](s? /,/) ")" "{" # WORKS: funcdefine: /function/i name "(" parameter[ $item[2] ](s?) ")" "{" # WORKS: funcdefine: /function/i name "(" parameter[ $item[2] ] ")" "{"

So it's a bug in Parse::RecDescent in the (... /,/) code. btw, (... /,/) is implemented as a <leftop>, so you could try using <leftop> directly (might not work), or try using the code said to be equivalent to <leftop> in the docmentaton (will definitely work), or use my little hack below (will definitely work).

# HACKED TO WORK: functiondefine: /function/i name "(" {@arg=($item[2]);1} parameter(s? /,/) ")" "{"

I only renamed functiondefine above so that the lines wouldn't wrap.

Replies are listed 'Best First'.
Re^2: Problem with Parse::RecDescent and subrule arguments
by richard5mith (Beadle) on Aug 26, 2004 at 17:04 UTC

    Yup, that little hacked version at the end works a treat. Thanks!