[antlr-interest] Duplicating Tree Nodes (in rewrite grammar)
Robin Hamilton-Pennell
robin at pozytron.com
Fri May 30 15:08:58 PDT 2008
Hi all,
Been stumbling against a problem lately which I'd like to get some feedback on.
I need to duplicate a tree node at a certain point in my AST rewrite
grammar, including all of its children (recursively). If I knew the
number of copies necessary in advance, I imagine I could do something
like this:
foo:
^(BAR baz) -> ^(BAR baz) ^(BAR baz) ^(BAR baz)
;
However, the number of copies necessary is not knowable until runtime.
I tried simply using CommonTree.dupNode(), but it doesn't copy the
children (after reading through the source I know this is correct
behavior).
So I guess my question is this: How can I make an arbitrary number of
copies of a tree node and all sub-trees? I don't actually care about
making changes to the tree yet, I just want a verbatim copy.
Any advice would be appreciated.
Thanks in advance,
Robin
More information about the antlr-interest
mailing list