On Oct 17, 2005, at 14:15, Patrick R. Michaud wrote:
I've just added a <PGE::Text::bracketed> subrule to PGE,
which is roughly analogous to the "bracketed" function in
Perl 5's Text::Balanced.
Like most PGE subrules, PGE::Text::bracketed can be called
as a subrule in a rule expression or directly via a subroutine call.
Thus, to extract quote-delimited text from a string:
.local pmc bracketed
bracketed = find_global "PGE::Text", "bracketed"
$P0 = bracketed("'this quoted string' and other stuff", "'")
returns a match object into $P0 that contains C< 'this quoted
string' >.
Delimiters can be escaped, thus
Shouldn't it contain C<this quoted string>? That is, shouldn't it
remove the bracketing characters? Or at least hold the string without
the brackets somewhere within the PGE::Text object? I'm getting:
<PunieGrammar::term> => PMC 'PunieGrammar' => "(ok 1)" @ 6 {
<PGE::Text::bracketed> => PMC 'PGE::Text' => "(ok 1)" @ 6
}
But want something more like:
<PunieGrammar::term> => PMC 'PunieGrammar' => "(ok 1)" @ 6 {
<PGE::Text::bracketed> => PMC 'PGE::Text' => "(ok 1)" @ 6 {
[0] => PMC 'PunieGrammar' => "ok 1" @ 7
}
}
So I can extract the parsed string. (If you squint and read "()" as
double quotes, it makes more sense.)
At the moment there's not a mechanism to specify an alternate set
of delimiters from within a subrule, but this should be available in
the near future as a subrule parameter:
<PGE::Text::balanced: {}()[]> # delimited by {}, (), []
<PGE::Text::balanced("<'\"")> # delimited by <>, ", '
I have a use for this as soon as its done (or is it already done?)
And thanks very much for adding this feature. It's a big help!
Allison