[stringtemplate-interest] [ST4] Warning when no variables declared in anonymous template

Sam Harwell sharwell at pixelminegames.com
Tue Feb 1 13:32:57 PST 2011


Hi Matthieu,

 

The warning you’re seeing is especially useful for users who previously worked with StringTemplate 3. In the old version, there was an implicit variable “it” that represented the iteration variable. In StringTemplate 3, the following two lines are essentially the same:

 

<values:{something}>

<values:{it|something}>

 

StringTemplate 4 no longer uses this implicit declaration. If it were me, and I was using an anonymous template that ignored the argument, I’d probably expect one of the following (I would personally write the first, but that’s just my style).

 

<values:{value|something}>

<values:{_|something}>

 

Sam

 

PS: Anonymous templates do not always need arguments, which is why the grammar allows that. For example:

 

bold(x) ::= "\<b><x>\</b>"

test() ::= "<bold(x={bold text})>"

 

From: stringtemplate-interest-bounces at antlr.org [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Matthieu Wipliez
Sent: Tuesday, February 01, 2011 12:03 PM
To: stringtemplate-interest at antlr.orgList
Subject: [stringtemplate-interest] [ST4] Warning when no variables declared in anonymous template

 

Hi,

the following

<values: {something}; separator="\n">

causes the following error:
"anonymous template has 0 arg(s) but mapped across 1 value(s)"

I think this error is a bit strange, because I don't need to declare a variable in this case, and I believe this is allowed by the grammar.

Declaring a variable in the template solves the problem, but I find it strange to declare a variable I know I won't need:

<values: {unused | something}; separator="\n">

Cheers
Matthieu

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110201/068ae496/attachment.html 


More information about the stringtemplate-interest mailing list