suaveant has asked for the wisdom of the Perl Monks concerning the following question:
I am using Parse::RecDescent to parse a meta language, and it is pretty much working, but I am having trouble with quoted strings. I have searched all around and can't find any good documentation on it.
In the P::RD docs it shows a parser for parsing P::RD grammars, and in that it shows { extract_quotelike($text) } being used as a rule. This doesn't do exactly what I want, since I only want ' and ", but it was close enough. I put it in my grammar like so:
and it works, I realize its probably not right, especially since I get lots of warnings for use of uninitialized values. When I tried to change my code to something more proper and kill the warnings, however, my grammar no longer works. I tried:string: { $_ = extract_quotelike($text); chop; substr($_,0,1,''); $_; +} { [@item] }
and it changes the way the whole grammar worksstring: { extract_quotelike($text) }
In fact if I change it to:
it breaks it as well... which really confuses me.string: { $_ = extract_quotelike($text); if($_) { chop; substr($_,0,1, +''); } $_; } { [@item] }
So, my real question is in two parts
1) how do you use the extract_quotelike in P::RD (I looked all through the docs for an explanation of what rule: { <code> } is supposed to do, but I can't find it. Is it undocumented or am I blind?)
2) Is there a better way to match a string with just single or double quotes?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Quoted Text rule for Parse::RecDescent?
by halley (Prior) on Aug 23, 2005 at 15:14 UTC | |
by suaveant (Parson) on Aug 26, 2005 at 18:06 UTC | |
Re: Quoted Text rule for Parse::RecDescent?
by ikegami (Patriarch) on Aug 23, 2005 at 17:18 UTC | |
Re: Quoted Text rule for Parse::RecDescent?
by TheDamian (Vicar) on Aug 23, 2005 at 20:39 UTC | |
by suaveant (Parson) on Aug 26, 2005 at 18:10 UTC | |
by TheDamian (Vicar) on Aug 27, 2005 at 00:55 UTC |