[antlr-interest] [v3] Token boundries unset for non-rightmost-edge rewrites

David Holroyd dave at badgers-in-foil.co.uk
Mon Nov 13 01:52:46 PST 2006


I have a rule like this:

identPrimary
    :   (identPart -> identPart)
        (    options{greedy=true;}
        :    (    DOT n=identPart
                  -> ^(PROPERTY_OR_IDENTIFIER $identPrimary $n)
             )
        |    (    LBRACK e=expression RBRACK
                  -> ^(ARRAY_ACC $identPrimary $e)
             )
        )*
        (    options {greedy=true;}
        :    a=arguments
             -> ^(METHOD_CALL $identPrimary $a)
        )*
    ;

I find that, for instance, the resulting PROPERTY_OR_IDENTIFIER
imaginary nodes have no start or stop values set.  Inspecting the
generated parser code, it looks like start/stop are only set for the
final result fragment that the rule as a whole produces.

I really need to see those values, so I tried splitting the rule above
so that the PROPERTY_OR_IDENTIFIER token will be the root, in a new rule:

identPrimary
    :   (identPart -> identPart)
        (    options{greedy=true;}
        :    (    test[$identPrimary.tree] -> test
             )
        |    (    LBRACK e=expression RBRACK
                  -> ^(ARRAY_ACC $identPrimary $e)
             )
        )*
        (    options {greedy=true;}
        :    a=arguments
             -> ^(METHOD_CALL $identPrimary $a)
        )*
    ;

test[Tree identPrimary]
    :    DOT n=identPart
         -> ^(PROPERTY_OR_IDENTIFIER {$identPrimary} $n)
    ;

However passing the $rulename reference to another rule like this
doesn't seem to work (no errors, but no subtree is added to the AST
either).

Am I doing something wrong, or are these things just not implemented yet?


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list