[antlr-interest] mysterious nil nodes...

Douglas Mayle douglas at mayle.org
Sat Jun 12 10:55:17 PDT 2010

Hi all, I'm using ANTLR v3.0.1 on ubuntu with a Python target and I keep getting nil nodes where I don't expect them.  For example, I have the following rule:

argument : ID COLON ID (EQUAL expression)? -> ^(ARGSPEC ID ID expression?)

I expect this to generate an ARGSPEC tree with three children.  Instead, I'm getting a nil root with one child (the ARGSPEC tree with three children).  I could simply add an action like so:
{ root_0 = root_1 }
and this would take care of the problem, but it definitely feels like the wrong way to handle things.  Is there something I'm doing wrong in my rule, or is this just normal and I should ignore it?  I should note that I'm using my own TreeAdaptor and nodes to create a custom AST, maybe the nil node is automatically ignored by the CommonTree code?

Douglas Mayle

More information about the antlr-interest mailing list