[antlr-interest] Stringtemplate / attribute mixup

Jim Idle jimi at temporal-wave.com
Tue Aug 10 15:47:50 PDT 2010


Does your smpl_arg rule return a value that is called label? If you post the
rules it might help. I use $st and custom return values all the time in java
based parsers. The other option is to just add the label to your list when
you are in the smpl_arg rule itself.

Jim



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Bill Andersen
> Sent: Tuesday, August 10, 2010 3:01 PM
> To: antlr-interest
> Subject: [antlr-interest] Stringtemplate / attribute mixup
> 
> 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
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address



More information about the antlr-interest mailing list