[antlr-interest] Problem splicing island grammar subtree into main AST
Mike J. Bell
ckimyt at gmail.com
Fri May 29 07:07:26 PDT 2009
OK, I finally figured out what my problem was...I'm not splicing an island
grammar AST into the main AST properly. Extrapolating from the island
grammar example, I made something like:
// note that a queue is required as there is delayed communication from
lexer to parser
SUBORDINATE
: '{'
{
SubordinateLexer l = new SubordinateLexer(input);
CommonTokenStream cts = new CommonTokenStream(l);
SubordinateParser p = new SubordinateParser(cts);
SubordinateParser.root_return subordinate = p.root();
subordinateQueue.queue((CommonTree) subordinate.tree);
};
subordinatebody returns [CommonTree node]
: SUBORDINATE { $node = subordinateQueue.dequeue(); };
subordinate
: s=subordinatebody -> ^($s);
So the problem here is that I don't want to splice in $s...I want to splice
in $s.node, which is the valid returned subtree that I made in the lexer.
But that's not valid syntax.
Any ideas on how I can get what I want? I thought about putting in a Java
code snippet that is mangled to get the $s.node manually, but I thought
that's a nasty solution that could break if ANTLR internals change in the
future. Surely there must be some way I can express this tree splicing in
ANTLR directly?
Thanks again in advance for any ideas...
--
Mike J. Bell on gmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090529/abe2324e/attachment.html
More information about the antlr-interest
mailing list