double back-slash in Parse::RecDescent grammars?

double back-slash in Parse::RecDescent grammars?

am 09.10.2006 23:43:03 von g_m

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

Re: double back-slash in Parse::RecDescent grammars?

am 10.10.2006 09:01:35 von g_m

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" 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
>
>
>