[antlr-interest] Recursive conditional template output.
Gavin Lambert
antlr at mirality.co.nz
Wed Aug 6 04:40:03 PDT 2008
At 21:30 6/08/2008, craig at palantir.co.za wrote:
>I want to iterate the template once for header output, and
>once for body output using the set of paths for each.
[...]
>But I cannot understand how to get the template to work as
>the recursion is implicit in the tree grammar, and 'item' is
>preempted from there, and not from the template. I need to
>iterate that section of the template twice, once for header
>output, and once for body output. Maybe dosomething(p) is
>not the right approach.
Something that I've seen used before when the entire tree needs
two different representations is to pass the same tree to two
separate tree grammars (or alternatively, the same grammar but
with different template expansions loaded). I think this was used
to eg. have one generate a .cpp and the other generate the .h.
On a smaller scale, I *think* you can switch the loaded template
expansions at runtime (within the grammar, with a bit of code),
which ought to do what you want. Unfortunately I can't give you
any specifics since I've never really used StringTemplate myself,
but hopefully this'll give you an idea of what to look for :)
More information about the antlr-interest
mailing list