[stringtemplate-interest] List-making problem

Roman Odaisky roma at qwertty.com
Mon Dec 1 02:29:44 PST 2008


On Monday, 01.12.2008 11:44:55 Mikael Nyberg wrote:

> For instance, I would like to be able to create list elements
> consisting of conditionally added subtemplates ($if()$...$endif$),
> lists with separators ($attr:{something:$it$}; separator=","$) etc.
> When I try to add expressions like these to a list using the
> $[...,...];separator=","$ list-making syntax, I get errors.
>
> Is there some syntactic element I'm overlooking here, or is the
> list-making syntax not meant to support arbitrary expressions as list
> elements?

There has been some discussion about replacements for $if$ in the thread 
starting from <200808101759.19093.roma at qwertty.com>.

In short, you can replace $if(condition)$template$endif$ with $condition:
{template}$. If  condition can be a list, use $first(condition):{template}$ 
to avoid expanding the template more than once. Instead of elseif you can use 
the null=... clause.

Also you can use any expressions in [] lists, for example, [attr, "literal", 
{template $something$}, "argument":template()]. This might solve your problem 
if I understand it correctly:

$[a, b, c, {$list; separator=", "$}, x, y, z]; separator="; "$

Or you could maybe define a standalone template like this:

(separated.st)
$it; separator=s$

and then invoke it as

$[a, b, c, list:separated(s=", "), x, y, z]; separator="; "$

(doesn’t seem to work, however :-).

-- 
HTH
Roman.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2286 bytes
Desc: not available
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20081201/72743ba0/attachment.bin 


More information about the stringtemplate-interest mailing list