For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > October 2006 > double back-slash in Parse::RecDescent grammars?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author double back-slash in Parse::RecDescent grammars?
~greg

2006-10-12, 6:58 pm

The documentation for Parse::RecDescent
says this:
========================================
==============
It is important to remember that, since each grammar is specified in a Perl string, all instances of the universal escape character
'\' within a grammar must be ``doubled'', so that they interpolate to single '\'s when the string is compiled. For example, to use
the grammar:
word: /\S+/ | backslash
line: prefix word(s) "\n"
backslash: '\\'
the following code is required:
$parser = new Parse::RecDescent (q{
word: /\\S+/ | backslash
line: prefix word(s) "\\n"
backslash: '\\\\'
});
========================================
===================

But what is that taking about???

Becaue none of the demos do that,
and nothing that I've gotten to work works by doing that.

As far as I can see, single \ works.
Double \\ does not work.


So what's the deal?

~greg



~greg

2006-10-12, 6:58 pm

I think it's that the example in the documentation is in error,
in that it uses single quotes q{...},
whereas it should use double quotes qq{...}.

(It'd make sense if it was double quotes,
but in single quotes the backslash is special only when
it occurs in front of the closing bracket: q{ ... \} ... },
'...'... ', etc.)

The real problem I'm having is that it seems to me that
Parse::RecDescent doesn't distinguish between \z and \Z.
I have to use /\n|\z/ (or /\n|\Z/) to do what /\Z/ is supposed to do.
Can anyone confirm if that's the case?

~greg





"~greg" <g_m@remove-comcast.net> wrote in message news:-7qdndByj7X9X7fYnZ2dnUVZ_v2dnZ2d@comcast.com...
> The documentation for Parse::RecDescent
> says this:
> ========================================
==============
> It is important to remember that, since each grammar is specified in a Perl string, all instances of the universal escape
> character
> '' within a grammar must be ``doubled'', so that they interpolate to single ''s when the string is compiled. For example, to use
> the grammar:
> word: /\S+/ | backslash
> line: prefix word(s) "\n"
> backslash: '\'
> the following code is required:
> $parser = new Parse::RecDescent (q{
> word: /\\S+/ | backslash
> line: prefix word(s) "\\n"
> backslash: '\\\'
> });
> ========================================
===================
>
> But what is that taking about???
>
> Becaue none of the demos do that,
> and nothing that I've gotten to work works by doing that.
>
> As far as I can see, single \ works.
> Double \\ does not work.
>
>
> So what's the deal?
>
> ~greg
>
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com