[antlr-interest] Stringtemplate / attribute mixup
Bill Andersen
bill.andersen at mac.com
Tue Aug 10 15:00:57 PDT 2010
Hi Folks
I have a rule, called 'alt', in a grammar with template output
alt
scope {
int argNum;
}
@init {
List<String> labels = new LinkedList<String>();
}
: ^(LIST_ALT { $alt::argNum = 0; }
( args+=smpl_arg { labels.add($smpl_arg.label); } )*
larg=list_arg?)
{ $rule::altNum++; }
-> listAlt(args={$args},larg={$larg.st})
;
Now, the args attribute is doing the accumulation of the templates being built by smpl_arg but I need to get some more information from smpl_arg, namely it's 'label' attribute, and collect those up into the list 'labels'
When I try to do the above I get an error in the generated Java
labels.add((args!=null?args.label:null));
"args.label cannot be resolved or is not a field"
I tried using $args.label and $arg.label (the last I was sure would not work but I had to try). Can anyone tell me how to do this without resorting to adding another list to catch the STs emitted by 'smpl_arg' via the .st attr?
Thanks
.bill
More information about the antlr-interest
mailing list