double back-slash in Parse::RecDescent grammars?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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?


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

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?


Quoted text here. Click to load it

Site Timeline