[stringtemplate-interest] misc
Colin Bean
ccbean at gmail.com
Mon Mar 26 09:40:42 PDT 2007
Hi Brian,
Haven't tested your first example, but you might try something like:
group test;
null ::= ["x":, default:]
test() ::= <<
$
["field1", "field2", "field3", "field4", "field5", "field6"],
["label1", "label2", "label3", "label4", "label5", "label6"],
["" , "" , null.x , null.x , null.x , "" ],
["40" , "40" , "40" , "40" , null.x , "40" ] :
{name, label, required, size|
$name$, $label$, $required$, $size$
};null="null"$
That should correctly replace all null instances in the list; not sure
if having a group called "null" confuses ST in any way.
It's also possible to iterate over a list of maps:
You can do something like this with an anonymous template to print map items
(haven't run this, so let me know if it doesn't work as expected).
$yourList:{$it.propX$ $it.propY$};$
Should work the same any other way you apply a template to a list.
HTH, post code if you're still having trouble.
Colin
On 3/26/07, Brian Lewis <bsl04 at uark.edu> wrote:
> group test;
> null ::= ["x":, default:]
> test() ::= <<
> $
> ["field1", "field2", "field3", "field4", "field5", "field6"],
> ["label1", "label2", "label3", "label4", "label5", "label6"],
> ["" , "" , null.x , null.x , null.x , "" ],
> ["40" , "40" , "40" , "40" , null.x , "40" ] :
> {name, label, required, size|
> $name$, $label$, $required:{};null="null"$, $size:{};null="null"$
> }
> $
> >>
>
> 1. What is the correct way to put null in a list?
>
> 2. The expected output was
> field1, label1, , 40
> field2, label2, , 40
> field3, label3, null, 40
> field4, label4, null, 40
> field5, label5, null, null
> field6, label6, , 40
>
> but the actual output was
> field1, label1, ,
> field2, label2, ,
> field3, label3, ,
> field4, label4, null,
> field5, label5, null,
> field6, label6, null, null
>
> Why?
>
> 3. I tried to iterate over a list of maps to save myself some repetitive
> coding, but it seems as though you can't have a list of maps. Is that
> correct?
> _______________________________________________
> 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