[antlr-interest] Processing a collection of tokens

Weiler-Thiessen, David, SASKATOON, Engineering David.Weiler-Thiessen at purina.nestle.com
Wed Jul 20 11:07:33 PDT 2011


Hi

 

I have the following in a tree grammar that works as I expect:

 

columnNameList returns [List names]    

                :               ^(COLUMN_NAMES ids+=ID+) 

                { 

                                $names = new ArrayList();

                                for( Object tree : $ids ) {

                                                $names.add( ((CommonTree)tree).getText().toUpperCase() );

                                }

                }

                ;

 

What I am wondering is if there is a built in way in ANTLR to loop over the list of ID tokens, to perform some common function, and then return that list.  I guess I am wondering if there is some built in 'collect' function similar to the collect method that is available on collections in languages like Groovy or Smalltalk.

 

I would prefer something like the following instead:

 

                $names = $ids.collect{ it.text.toUpperCase() }

 

How is this usually handled? 

David Weiler-Thiessen 
Nestlé Purina PetCare 
phone: 306-933-0232 
cell: 306-291-9770 

This e-mail, its electronic document attachments, and the contents of its website linkages may contain confidential information. This information is intended solely for use by the individual or entity to whom it is addressed. If you have received this information in error, please notify the sender immediately and promptly destroy the material and any accompanying attachments from your system.



More information about the antlr-interest mailing list