in reply to Regexp::Common inside Parse::RecDescent

You'll have to have the use inside the parser code, i.e. in the generated code. This means you should use a start-up action since the first thing to do when the parser starts is to load the module. Try this for the grammar:

my $g = q( { use Regexp::Common qw(URI); } CommentLine: '#' /.*/ {{comment=>$item[2]}} UriLine: 'u=' /$RE{URI}{HTTP}/ {{uri => $item[2]}} Line: CommentLine | UriLine {$item[1]} );
See Parse::RecDescent's POD under 'Start-up actions' for details.

IMHO, the grammar should definitely be in single quotes since it should not be interpolated in contrast with what Abigail-II says.

Hope this helps, -gjb-

Replies are listed 'Best First'.
Re: Re: Regexp::Common inside Parse::RecDescent
by demerphq (Chancellor) on Aug 21, 2003 at 17:49 UTC

    IMHO, the grammar should definitely be in single quotes since it should not be interpolated in contrast with what Abigail-II says.

    You're both wrong. :-)

    No just kidding. You are both right. Abigails suggestion would work fine if the $RE expanded before P::RD ever saw it. OTOH, it makes more sense to me to use your approach of use()ing the module inside of the grammar.

    And personally I prefer single quoted here docs for my grammars because it avoids the double interpolation problem that can crop up unexpectedly if you arent careful.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

      I suggest using here-docs for grammars.

      #!perl use warnings; use strict; my $one = q{/\d \\ \/ \\/ / }; my $two = <<'--snip--'; /\d \\ \/ \\/ / --snip-- print "\$one is `$one'\n\$two is `$two'\n"; __END__

      This prints

      $one is `/\d \ \/ \/ / ' $two is `/\d \\ \/ \\/ / '
      which means you needn't escape your backslashes in single-quote here-docs. This can make regexes more readable.