[antlr-interest] Stringtemplate/ANTLR - building up multivalued attribute

Jim Idle jimi at temporal-wave.com
Wed Jul 14 10:52:30 PDT 2010


a+=alternative+

alts={$a}

You will get a list passed in to the template argument instead of a single template and can then iterate. This is in the ANTLR book btw.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Bill Andersen
> Sent: Wednesday, July 14, 2010 10:45 AM
> To: antlr-interest
> Subject: [antlr-interest] Stringtemplate/ANTLR - building up
> multivalued attribute
> 
> Hi Folks
> 
> I have a production in a tree grammar with ST output
> 
> rule
> 	: ^(AS_RULE rName=ID rType=ID alternative+)
> 	;
> 
> What I'd like is to pass in all the STs from the 'alternative' matches
> into a single multi-valued attribute for the ST for this production,
> like so
> 
> rule
> 	: ^(AS_RULE rName=ID rType=ID alternative+)
> 	  -> someTemplate(rName={$rName.text}, alts={ ??? })
> 	;
> 
> where alts iis a multi-valued attribute consisting of STs.  I know I
> can do this
> 
> rule
> @init { List<StringTemplate> alts = new ... }
> 	: ^(AS_RULE rName=ID rType=ID ( a=alternative { alts.add($a.st);
> } )+ )
> 	  -> someTemplate(rName={$rName.text}, alts={ alts })
> 	;
> 
> but this seems clumsy.  Is there any better way?
> 
> Thanks.
> 
> 	.bill
> 
> Bill Andersen
> Highfleet, Inc. (www.highfleet.com)
> 3600 O'Donnell Street, Suite 600
> Baltimore, MD 21224
> Office: +1.410.675.1201
> Cell: +1.443.858.6444
> Fax: +1.410.675.1204
> 
> 
> 
> 
> 
> 
> 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