[antlr-interest] AST loosing leaves in 3.3 vs. 3.2

Joseph Cottam jcottam at umail.iu.edu
Tue Jan 4 15:47:41 PST 2011


Upgrading from v3.2 to v3.3, I started loosing the leaves in some of my
rules.  All affected rule-pairs have the same structure: The results of
called rule becomes the root of the AST returned by the rule doing the
calling AND the calling rule adds more nodes to the AST (not just returning
the results of the called rule).  In the example below, the result of
matching the "call" rule is truncated to just its root when it is referred
to in the construction of the AST for "callTarget."  I feel like I am
missing something simple, but I can't figure out what part of the v3.3
release notes covers this circumstance.

3.2 output: (FUNCTION first second third PACK)
3.3 output: (FUNCTION PACK)

-Joseph A. Cottam


input------------------------
first second third

grammar-------------------
grammar Error;

options {
  language = Java;
  output=AST;
}

tokens {FUNCTION; PACK;}

callTarget
 : call
    -> ^(call PACK)
 ;

call
  : one=ID two=ID three=ID
    -> ^(FUNCTION $one $two $three)
  ;

ID    : ('a'..'z' | 'A'..'Z' | '_') ('.'? ('a'..'z' | 'A'..'Z' | '_' |
'0'..'9'))*;
WS  : (' '|'\r'|'\t'|'\u000C'|'\n')+ {skip();};


More information about the antlr-interest mailing list