[antlr-interest] How to access member of CommonTree subclass
Jim Idle
jimi at temporal-wave.com
Mon Oct 26 16:18:21 PDT 2009
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Kaleb Pederson
> Sent: Monday, October 26, 2009 3:55 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] How to access member of CommonTree subclass
>
> I'm working with a tree parser that is creating ASTs of a custom type.
> This CommonTree subclass contains a member named elementType that
> identifies the type represented by the tree. How do I set the
> elementType dynamically within an action?
>
> I tried in the following way:
>
> id:
> ^(AST_ID tok+=ID+)
> {
> $tree.setElementType( typeResolver.resolve(StringUtils.join($tok,
> ".")) );
> }
> ;
>
> This, however, doesn't work since the tree has not yet been set:
I presume that this is a tree walker that is producing another AST as output?
Anyway, why not return the value of typeResolver from the id rule, then set the resulting tree value?
id : resolveID { $resovleID.tree.setElementType($resolveID.type); } ;
resolveId
returns [ xxx type]
: ^AST_ID tok+=ID+) { $type = typeResolver.resolve(StringUtils.join($tok,".")) );
;
Jim
More information about the antlr-interest
mailing list