[antlr-interest] Question about tree grammar (antlr 3)
Kay Roepke
kroepke at dolphin-services.de
Tue Jul 4 09:11:47 PDT 2006
On 4. Jul 2006, at 17:51 Uhr, Terence Parr wrote:
>> setDir : ^('dir' LITERAL {s.setDirIn(((Tree)$LITERAL).getText());})
>>
>> Do somebody know one better, without cast?
>
> You can try setting ASTLabelType as a grammar option or more simply
> do this:
>
> setDir : ^('dir' LITERAL {s.setDirIn($LITERAL.text);}) ;
As an alternative you could also do
setDir : ^('dir' LITERAL {s.setDirIn(($LITERAL.tree).getText());})
to get rid of the explicit cast. But in this it probably doesn't make
sense, since
the text is much easier accessable per Ter's suggestion.
See Java.stg for the templates that make it happen (very close to the
end of the file).
-k
More information about the antlr-interest
mailing list