[antlr-interest] Stringtemplate/ANTLR - building up multivalued attribute
Bill Andersen
Andersen at highfleet.com
Wed Jul 14 10:45:15 PDT 2010
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
More information about the antlr-interest
mailing list