On Wed, Oct 01, 2008 at 11:24:04PM -0400, Brandon S. Allbery KF8NH wrote: > On 2008 Oct 1, at 22:23, Timothy S. Nelson wrote: >> On Wed, 1 Oct 2008, Brandon S. Allbery KF8NH wrote: >>> On 2008 Oct 1, at 22:14, Timothy S. Nelson wrote: >>>> Hi all. I've enjoyed(?) reading over the February/March thread >>>> entitled "Musings on operator overloading". I've brought a few thoughts >>>> along; if they're old news, please tell me >>>> here to do more reading on it :). >>> >>> The Perl6 way to do this is grammars; using an XML grammar to pull data >>> out of an XML document is one of Larry's favorite examples. >> >> Ok, great. While I see how this does a great job of converting the >> string of data into a plex, it doesn't solve the problem of selecting the >> data from the plex in a glob-like (or XPath-like) fashion, which is what >> I'm talking about here. Have I missed something that will do that? > > I could have sworn there was a short and elegant example of using a grammar > to extract arbitrary information from an XML document, but I don't see it > in the documentation. I recall Trey Harris showing such an example on IRC > but not in a logged channel; maybe he'll see this message and jump in, or > if not I'll see if I can get him to write another example.
The key point Brandon is making, that I'm not sure you're answering, is that he wants to extract elements of a tree-like data structure (think DOM), not simply from a string representation of a structure (such as an XML document in a string). Thinking in terms of grammars, I'd ask the question: could grammars be used to match tree-like data structures? I think the current answer is no. Grammars are too tightly bound to the concept of a position in a linear string. But I have a nagging suspicion that this is a very powerful idea. Applying the expressive power of a grammar-like mechanism to search, backtrack, and match within a tree-like data structure. Is this new or has anyone discussed it before? Tim.