I need to parse some streams of unicode text. I'd like to use Parse::RecDescent. My specific problem is I am having trouble getting Parse::RecDescent to accept characters in the form '\N{...}'. Here's an example:
use strict;
use charnames ':full';
use Parse::RecDescent;
$::RD_TRACE = 1;
$::RD_HINT = 1;
my $parser = new Parse::RecDescent(<<'EOG') || die;
ex1: "\N{DIAMOND OPERATOR}" {warn 'got it'} # fails despite 'use char
+names'
ex2: "\x{22c4}" {warn 'got it'} # always works
ex3: /\p{Letter}/ {warn 'got letter'} # fails unless 'use charnames..
+.'
EOG
The hint offered by the parser states 'Constant(\N{...}): $^H{charnames} is not defined'.
It's interesting to note that the line 'ex3' fails if charnames isn't used, so P::RD seems to sort-of know about about charnames.
Alternatively, if anyone has dealt with unicode in P::RD grammars, I'd like to hear your opinions and experiences (hopefully not too grim).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.