As some of you probably know, since revision 948, TextMate supports the ability to have the entire document together with all the scope information as input for command. This is done by setting a key "inputFormat" with value "xml" into the plist file for the command, and setting the input to the command to be the entire document. This will input the document in a "pseudo-xml" format, of the type: <scopename>text</scopename>, with nestings etc.
The ScopeHandler class is a Ruby class I just put together that offers you an easy interface to this “xml”-style input. I've set up a home page for this class with a couple of descriptions and examples here: http://skiadas.dcostanet.net/afterthought/the-scopehandler-class/ The actual file can be found here: http://skiadas.dcostanet.net/uploads/scopeHandler.rb Use at your own risk. Let me know if you do. Feel free to suggest additions/corrections/more examples/ideas for use.
Haris