[stringtemplate-interest] Get parameters of a StringTemplate

Terence Parr parrt at cs.usfca.edu
Tue Oct 23 01:52:13 PDT 2007


On Oct 23, 2007, at 12:50 AM, palinf wrote:

> Hi,
>
> I am trying to get the list of parameters (i.e. things which should be
> replace in the template).

Hi. This can get complicated for things other than simple <foo>  
references.  For example, <foo()> instantiates another template so  
you have go look at that one.  But, polymorphism means it's not super  
simple...

I think if you look at the StringTemplate object, you might find a  
few helpful methods for printing what you have set but not what you  
*can* set.

Ter

> The method StringTemplate.getParameter() return null when no  
> parameters
> have been set.
>
> I wrote this small piece of code to get them but I am sure this is not
> the way to do it.
>
>       * private* List getParameters(StringTemplate st) {
>                 List chunks = st.getChunks();
>                 List l=* new* ArrayList();
>                * for* (Iterator iter = chunks.iterator();
> iter.hasNext();) {
>                         Object element = (Object) iter.next();
>                        * if* (element* instanceof* ASTExpr) {
>                                 ASTExpr new_name = (ASTExpr) element;
>                                 l.add(new_name.toString().trim());
>                         }
>         }
>                * return* l;
>         }
>
>
> Is there a simplest way to do it ?
>
> Regards,
>
> Olivier
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list