[stringtemplate-interest] How best to do recursive hetero template calls?
Terence Parr
parrt at cs.usfca.edu
Fri Feb 19 13:39:52 PST 2010
On Feb 16, 2010, at 2:49 PM, Gerald Rosenberg wrote:
> Hi Ter,
>
> Yes, slippery slope and all that. Quite agree with the argument against
> model view entanglement -- actually the argument is mostly against
> putting combinatorial logic in the view to evaluate model aspects.
Yup.
> To explain a bit, the attribute being provided to the view is not some
> fancy data structure, but a simple, literal representation of the view
> to be generated. Nested templates are a direct map to the view - each
> node's type field is the literal name of the template to be applied to
> the node.
ah. ok, if there is no logic, then I think it is okay to use recursion to walk the tree to spit out XML or whatever.
> A two-dimensional walk in ST (no exceptions, no conditionals)
> should be functionally little different from a one-dimensional ST list
> iteration. So, this narrow use of recursion should not be too much of an
> entanglement violation, right?
should be okay; after all, that's how ST v3 he evaluates trees of templates ;)
> Given the view representation is heavily nested, if I instead use
> external walker I wind up having to not just choose node templates, but
> also have to provide the decision logic to stitch together parent entry
> and exit templates for each node. And, manage the correspondence
> between the walker logic and the model and all of the view templates.
> Doable, but seems clumsy.
>
> Anyway, I have started to experiment using ST4 and, so far, looks
> promising.
>
> Purely functional hetero template calls work nicely!
> <(first(element.children).type)(...)>
sweet...
> Only issue found is that STGroup#getInstanceOf(String name) needs a null
> check on name - the rest operator can return a null list and that can
> result in an NPE when rest is used to provide an attribute to another
> template.
Fixed.
Ter
More information about the stringtemplate-interest
mailing list