[antlr-interest] Nested Closures -> Nested AST Generation

Johannes Luber jaluber at gmx.de
Sat Jul 7 10:55:18 PDT 2007


Randall R Schulz wrote:
> Hi,
> 
> Here is a fragment of a AST-generating grammar I have:
> 
> atom
>   : ( '('
>         predicate = term
>         '('
>           RoleSet ( '(' role = name arg = term ')' ) *
>         ')'
>       ')'
>     )
>   ->  ^( RoleSet $predicate ^( RoleArg $role $arg ) * )
>   ;
> 
> 
> I've discovered (through the miracle of DOTTreeGenerator!) that no 
> matter how many repetitions of the ( role=name arg=term ) tuples appear 
> following the RoleSet token, only one RoleArg subtree is present in the 
> synthesized AST. That single RoleArg subtree's values always correspond 
> to the last repetition of the RoleSet tuples that was present in the 
> input.
> 
> Am I doing this wrong, or is this a bug?
> 

Try "RoleSet ( '(' role+=name arg+=term ')' ) *".

Best regards,
Johannes Luber


More information about the antlr-interest mailing list