|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Re: Quoted Text rule for Parse::RecDescent?by halley (Prior) |
| on Aug 23, 2005 at 15:14 UTC ( #485935=note: print w/ replies, xml ) | Need Help?? |
|
If you don't want anything but ' and " strings, then just fail the rule if $item[...][1] ne "'" and $item[...][1] ne '"'. In my application, I allow qr// and ' and ", but not others like qq//, qx//, s/// or tr///. In qr//, I scan for any use of (?{...}) and fail for those. I just bring it up to show that you can choose your rules pretty flexibly. (Expanded answer.) As for "how to use the code blocks in a production," just realize that there's no real difference between the parsing parts and the code parts: if you get through all of the subrules in the production, then the whole production succeeds and passes whatever is in $return up to the calling rule. The code blocks in YACC are very distinct, but code blocks in P::RD are more like embedded (?{}) code in a regexp. (That was my revelation thanks to another monk a few weeks ago.) So, do whatever you want in a code block. The items so far are in @item and %item. You can assign whatever you want to assign into $return, including undef to fail the rule.
--
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||