On Dec 7, 2005, at 15:34, Patrick R. Michaud wrote:
For this I was following the design of "extract_bracketed" in
Perl 5's Text::Balanced, which returns the delimiters as part
of the string. I agree it would be nice for PGE::Text::bracketed
to also return the string without the outer delimiters somewhere.
But this begs a larger design issue -- should it be able to return
all nested and balanced substrings without their delims (and if so,
what should the resulting Match object structure look like)?
Most uses past "give me a chunk of text between these delimiters" are
complex enough to require custom parsing. That is, you rarely care
about just the bracketing delimiters; you generally also want to
parse other information between the delimiters, and so would end up
writing your own rules for it anyway. It also seems like it might be
somewhat expensive to generate the whole tree. Those are two reasons
to say "we'll give you the small step of the contained string without
the bracketing delimiters, but for anything more complex, write your
own rule".
Anyway, it's no problem for me to update PGE::Text::bracketed to
return a sub-match of the string without its outer delimiters, if
we want to go that way.
I'd certainly use it right away.
It's already "done", but only using the colon+string argument version
above, and I have this nagging suspicious that syntax is going to be
removed from the spec (if it hasn't been removed already).
But at the moment, a string can be matched based on balanced and
nested parentheses using
<PGE::Text::balanced: ()>
Ah-ha! This works:
p6rule('\d+ | <PGE::Text::bracketed: ">', 'PunieGrammar', 'term')
(I experimented with several variations of syntax today, but hadn't
hit on one that worked yet.)
Allison