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

David Holroyd dave at badgers-in-foil.co.uk
Tue Nov 14 00:52:40 PST 2006


On Mon, Nov 13, 2006 at 09:52:46AM +0000, David Holroyd wrote:
> 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)
>     ;

Another problem with the above is that the 'test' rule I added doesn't
actually see the token that I want to be the 'start' of that subtree
anyway.  I have got soething working for PROPERTY_OR_IDENTIFIER nodes,
but it's rather convoluted:

identPrimary
    :    (identPart -> identPart)
        (    options{greedy=true;}
        :    (    poi=propOrIdent[root_0, retval.start] -> $poi
             )
        |    (    LBRACK expr=expression RBRACK
                -> ^(ARRAY_ACC $identPrimary $expr)
             )
        )*
        (    options {greedy=true;}
        :    a=arguments
             -> ^(METHOD_CALL $identPrimary $a)
        )*
    ;

propOrIdent[Tree identPrimary, Token startToken]
    :    
        { retval.start = startToken; }
        DOT propId=identPart
        -> ^(PROPERTY_OR_IDENTIFIER {$identPrimary} $propId)
    ;


Is there any way I could simplify this?


ta,
dave

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


More information about the antlr-interest mailing list