From http://phrogz.net/RubyLibs/rdoc/OWLScribble/doc/tts.html:

"The TagTreeScanner class provides a generic framework for creating a  
nested hierarchy of tags and text (like XML or HTML) by parsing text.  
An example use (and the reason it was written) is to convert a wiki  
markup syntax into HTML."

It's not yet as easy as I'd like to understand the core concepts, but  
in a nutshell you specify a series of states which your parser may go  
through, and for each state supply a set of tags to look for in that  
state. Though both it and the Syntax library use StringScanner (and  
thus regular expressions) to do the job, TagTreeScanner is distinct  
in that:

1) It automatically handles the opening and closing of tags for you  
(particularly the "close_match" property of a TagFactory)

2) It automatically handles state (the @tag_genres hash and the  
allowed_genre property of factories)

3) It keeps track of a nested tree during building, automatically  
pushing and popping nodes as necessary, and (when no tags can be  
found) pushing text into the current tag.

I'm not yet cool enough to put this into a gem...hopefully I'll do  
that in the next week or so.

This library is useless by itself; it exists to allow you to define  
your own syntax parser as a subclass of TagTreeScanner. Which is what  
I've done with the OWLScribble class, documented along side  
TagTreeScanner.

I appreciate all feedback, positive and negative, about the  
efficiency of the code, clarity of the documentation, or interface to  
the class.


--
"When I am working on a problem I never think about beauty. I only  
think about how to solve the problem. But when I have finished, if  
the solution is not beautiful, I know it is wrong."
- R. Buckminster Fuller