[stringtemplate-interest] problem with null handling in parallel iteration
Brian Lewis
bsl04 at uark.edu
Wed Apr 4 01:58:30 PDT 2007
Would someone with a few free minutes *please* check the following
StringTemplate group and java code? I think it demonstrates a problem
with null handling in parallel iteration.
The output is
field1, label1, , 40
field2, label2, ,
I hope you will agree that the output *should* be
field1, label1, , null
field2, label2, , 40
test.stg:
group test;
/* "hack" gets me null. why isn't there an \N? */
hack ::= ["x":, default:]
test() ::= <<
$
["field1", "field2"],
["label1", "label2"],
["" , "" ],
[hack.x , "40" ]:
{name, label, required, size|
$name$, $label$, $required$, $size$
};null="null"$
>>
Test.java:
import java.io.*;
import java.util.*;
import org.antlr.stringtemplate.*;
import org.antlr.stringtemplate.language.*;
public final class Test
{
public static void main(String[] arguments)
{
Test t = new Test();
t.test();
}
public void test()
{
InputStream ins = getClass().getResourceAsStream("test.stg");
InputStreamReader in = new InputStreamReader(ins);
StringTemplateGroup g = new StringTemplateGroup(
in,
DefaultTemplateLexer.class
);
StringTemplate st = g.getInstanceOf("test");
System.out.println(st.toString());
}
}
More information about the stringtemplate-interest
mailing list