[antlr-interest] Perplexed about template option

ima_band at comcast.net ima_band at comcast.net
Thu Dec 13 12:37:54 PST 2007


Hi,

To my sheer delight I am generating tons of code with ANTLR without having to deal with the more complex AST trees. But since I'm using the template option all of my rules return an implicit string template, right? Trouble is, unless I'm mistaken, this ties you into having template output that mimics the hierarchy (i.e. nesting) of your input data. When I created a DataObject wrapper it worked fine but my Bean implementation needed field name and type data in two separate parts of the file. At first I imagined being able to invoke 2 different templates from my columnDef rule and pass them up and into my outermost template as two separate parameters. As far as I can tell that is not possible. Instead I created an aggregate FieldDef class in the @members area and added them to a fieldDefList as columns where recognized down in the columnDef rule then passed the list of aggregates to the outermost template and leveraged StringTemplates various iterator features.  

I was forced to abandon what I thought was the stated intent of the template option (bubbling up STs) and piece together a bunch of Java code instead. Don't get me wrong, applying templates to multi-valued attributes is pretty cool and gets me where I want to be. But if you could emit multiple STs for the same rule then you could simply pass them to the outermost template and stick them where they need to be! No muss. No fuss. No unneeded class definitions.

Thoughts?

Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071213/5a57a716/attachment.html 


More information about the antlr-interest mailing list