in reply to Quoted Text rule for Parse::RecDescent?
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.
string: <perl_quotelike> { if ($item[1][0] =~ /^(qx|s|tr|y)$/ or # no perl commands $item[1][1] eq '`' or # no backticks $item[1][2] =~ /\(\?\??\{/) # no qr'' with code { $return = undef } else { $return = eval "" . join('', @{$item[1]}) } (defined $return) }
--
[ e d @ h a l l e y . c c ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Quoted Text rule for Parse::RecDescent?
by suaveant (Parson) on Aug 26, 2005 at 18:06 UTC |