[antlr-interest] String template questions.
Terence Parr
parrt at cs.usfca.edu
Mon Apr 7 10:22:08 PDT 2008
On Apr 7, 2008, at 9:21 AM, PSheehan at decaresystems.ie wrote:
>
> I've got a simple grammar up and running which generates Java beans
> and Hibernate config files. I have a few questions as I'm not
> really sure if I am going about things in the correctly way. My
> solution uses a lexer and parser to create an AST which I then pass
> on to a tree walker for the generation of the output.
>
> 1. How do people generally create multiple files from a single
> tree output. For example if the result of the tree needs to create
> Bean1.java and Bean2.java. Currently I've created a streamer
> strategy which my tree walker calls when it needs be, passing the
> output of a template to it. The strategy then knows how to create
> java files in the correct package structure. I can then easily
> change the strategy in order to write Hibernate config files. Is
> this a valid approach or should I just get the tree walker to roll
> up all the template results and break them up after the walker has
> finished.
You could create an ST "broadcaster" that emits same attributes to
multiple templates or just set attr ofmultiple templates manually.
> 2. I've created one entry point into my templates from my grammar
> like so '%modeltmp($namespace,$name,$fieldDefinations)'. Only one
> rule in the tree walker invodes a grammar, the other rules just
> gather the information needed to pass to the template. The main
> reason I did this was so I could call different templates from
> within the main template to produce different output given the same
> input. For example I could generate a constructor, bean properties
> and a 'toString' method all from $fieldDefinations. Is there a
> better way of doing this?
That works great.
> Should I move some of this work back into my parser so it creates,
> in the AST, a constructor node with field definations as childern or
> a 'toString' node with field definations as childern etc.
easier to emit multiple thigns than create multiple trees usually.
>
Ter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080407/f46a849f/attachment.html
More information about the antlr-interest
mailing list