Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Using Parse::RecDescent to parse Perl-ish strings without resorting to string eval

by polypompholyx (Chaplain)
on Feb 29, 2008 at 20:08 UTC ( #671279=note: print w/ replies, xml ) Need Help??


in reply to Re: Using Parse::RecDescent to parse Perl-ish strings without resorting to string eval
in thread Using Parse::RecDescent to parse Perl-ish strings without resorting to string eval

Yes, in the original code, there's some fiddling with <skip> (since whitespace has syntactic significance in the grammar), and unescaping of Unicode hex character escapes. I left them out for clarity.

I can probably live with handrolled code that parses its own definition of a double quoted string, since most of the interpolation is unnecessary, but I'm not sure of any way out with regexes: I'd like to be able to do something like:

$text = qr/$text/$modifiers

but $modifiers doesn't interpolate, and I can't think of any easy way to simulate this without having a very large switch statement.


Comment on Re^2: Using Parse::RecDescent to parse Perl-ish strings without resorting to string eval
Select or Download Code
Re^3: Using Parse::RecDescent to parse Perl-ish strings without resorting to string eval
by ikegami (Pope) on Feb 29, 2008 at 20:20 UTC
    my $mods_p = ''; my $mods_m = ''; ($opts{$_} ? $mods_p : $mods_m) .= $_ for qw( x i s m ); $re = qr/(?$mods_p-$mods_m:$re)/;
      Ah, of course. I am an idiot. ikegami++

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2015-07-06 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (71 votes), past polls