[antlr-interest] Root note of tree doesn't have the index attribute?
Gavin Lambert
antlr at mirality.co.nz
Sun Mar 23 17:12:55 PDT 2008
At 12:45 24/03/2008, Bernardo Elayda wrote:
>myrule : ^(a='=' b=NODE c=NODE) -> mytemplate(mya={$a.index},
>myb={$b.text},myc={$c.text}) ;
>
>When I compile the above rule and compile the resulting java
>file, I get an error that says it cannot find the method
>getTokenIndex for 'a'. That doesn't make sense to me. Isn't the
>root node labeled as 'a' above just a token? If I change the
>above template to use $a.text, that works.
Each element within a tree parser is a tree node, which *contains*
a token (and a collection of child nodes), but it's not a token
itself.
There should be a way to get to the token itself, but I haven't
really used tree grammars before myself so I can't tell you what
it would be offhand. If nobody else pipes up then your best bet
would be to have a look at the generated code, particularly at the
definition of the class it uses for the node.
(Although I do seem to recall also hearing that literal strings
didn't work in tree grammars. But that was a long long time ago
so maybe that's been sorted out.)
More information about the antlr-interest
mailing list