[antlr-interest] Duplicate nodes in different forms
Stefan Bischof
stefan.bischof at deri.org
Wed Jun 17 11:03:09 PDT 2009
Hi guys!
I'm writing a source to source translator for a XQuery extension with
ANTLR and was very happy so far. I have created an AST and now want to
write a tree parser rewriting our custom parts of that AST to get a pure
XQuery AST. So I've created a tree parser using rewrite=true and
filter=true.
I have some special cases I couldn't find a solution in the book nor by
trying:
I have a list of variables and want to do two things with it
1. just put them there again
2. for every variable in that list: create some more variables with
different prefixes.
Simplified example what I want to do:
$i=VAR+ ->
$i+
VAR[$i, "_" + $i.text]+
VAR[$i, "?_" + $i.text]+
I've tried different variants of that and couldn't get a valid solution.
I either get an Exception (see example at the end):
java.lang.IllegalArgumentException: Can't set single child to a list
or the successfully created Java code doesn't compile because a while
loop with an empty condition is generated:
while ( ) and while ( ! ( ) )
So, any ideas how this could be or should be handled?
best regards,
Stefan Bischof
---------------------------
Simplified example for "Can't set single child to a list":
^(INTEGERS INT+) -> INT+
leads to:
java.lang.IllegalArgumentException: Can't set single child to a list
at org.antlr.runtime.tree.BaseTree.setChild(BaseTree.java:144)
at
org.antlr.runtime.tree.BaseTreeAdaptor.setChild(BaseTreeAdaptor.java:225)
at org.antlr.runtime.tree.TreeVisitor.visit(TreeVisitor.java:36)
at org.antlr.runtime.tree.TreeVisitor.visit(TreeVisitor.java:33)
at org.antlr.runtime.tree.TreeRewriter.downup(TreeRewriter.java:89)
(so the rewriting itself actually works, but the list can't be added as
a child to the parent node, i assume)
--
Stefan Bischof <stefan.bischof at deri.org>
DERI Galway
More information about the antlr-interest
mailing list