[antlr-interest] Tree grammar/stringtemplate: do I need this?

Steve Bennett stevagewp at gmail.com
Sun Jan 20 05:54:54 PST 2008


Hi all,
  I've got a medium sized parser for a wiki language which generates a
nice AST. I'd now like to be able to dump out the AST as HTML. Almost
all of the processing and validation has already taken place at this
point.

I thought a tree grammar and string templates would be the way to go.
But according to the book, I should "begin by copying the parser
grammar...and hten altering the header". Eep! Although my parser is
only 760 lines so far, it is bound to grow, and I hate the idea of
having to keep the two parsers synchronised. Also, so much of what
tree grammars do seems redundant for my purposes: there is no "high
level structure" to be validated.

All I really want is something to convert an AST node such as this:

OL
+LI
++foo
+LI
++bar

into text like this:

<ol>
<li>
foo
</li>
</li>
bar
</li>
</ol>

Is there a simpler way?

(I do want to do a small amount of intermediate processing, like
concatenating the children of certain nodes, but maybe that's a
separate issue...)

Thanks for any advice!

Steve


More information about the antlr-interest mailing list