Re: locale problem with P::RD

[email protected] ("Ron D. Smith") Wed, 14 Jul 2004 17:33:22 -0700
Newsgroups perl.recdescent
Message-ID <[email protected]>
On Wednesday, Jul 14, 2004 Karl Gaissmaier said:
> Hi,
> =

> I nearly finished Config::Scoped, yet another config
> file parser but I am currently busy with an annoying
> locale problem. I'm for example not able to match
> german umlaute with the rule pattern /\w/ even with
> the proper LC_... env and 'use locale' in P::RD.
> =

> With a plain pattern match 'string' =3D~ /\w+/ it's working!
> =

> Please check my stripped down code snippet:
> =

> #-------- locale_test.pl --------------------
> use locale;
> use Parse::RecDescent;
> =

> $grammar =3D 'char : /\w/ {print "P::RD $item[1] matched\n"}';
> =

> Parse::RecDescent->new($grammar)->char('=E4')
>      or warn "P::RD =E4 didn't match\n";
> =

> Parse::RecDescent->new($grammar)->char('a')
>      or warn "P::RD a didn't match\n";
> =

> # and now with plain regexp
> '=E4' =3D~ /\w/ ? print "/\\w/ =E4 matched\n"
>              : warn  "/\\w/ =E4 didn't match\n";
> =

> 'a' =3D~ /\w/ ? print "/\\w/ a matched\n"
>              : warn  "/\\w/ a didn't match\n";
> =

> exit 0;
> #----------------------------------------------
> =

> and with the proper LC_CTYPE set:
> =

> wega$ LC_CTYPE=3Diso_8859_1 perl locale_test.pl
> P::RD =E4 didn't match
> P::RD a matched
> /w/ =E4 matched
> /w/ a matched
> =

> =

> you see, with /\w/ we match the german umlaut '=E4'
> but not as a pattern literal in P::RD.
> =

> And for completeness:
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> This is perl, v5.8.4 built for sun4-solaris
> P::RD::VERSION =3D '1.94'
> wega$ locale -a
> POSIX
> C
> iso_8859_1
> =

> Any hints welcome, perhaps I don't see the wood
> for the trees.

I cannot reproduce your problem because our install does not accept the =

locale.  However if you look at the RD_TRACE that gets produced (which sh=
ows =

you the *actual* code produced by PR::D) you will notice that /\w/ is not=
 =

*directly* translated, but instead becomes 's/\A(?:\w)//'.  Perhaps this =

explains what you see, perhaps not.

> =

> Best Regards
> 	Charly
> =

> -- =

> Karl Gaissmaier       KIZ/Infrastructure, University of Ulm, Germany
> Email:[email protected]           Service Group Network


--
 Intel, Corp.
 5000 W. Chandler Blvd.
 Chandler, AZ 85226

-- =

 Intel, Corp.
 5000 W. Chandler Blvd.
 Chandler, AZ  85226