[stringtemplate-interest] problem with null handling in parallel iteration

Terence Parr parrt at cs.usfca.edu
Sun Apr 22 17:33:45 PDT 2007


Hi. null is not the same thing as an empty string.  I believe that  
when you define "x": in a map it will map to an empty string rather  
than null. That might be a side effect of my implementation.  I do  
not think too much about that.  Should it be null or an empty string?  
most of the time the difference doesn't matter unless you are  
iterating I guess. you will actually be sending in data from your  
model, right? the hack map will not be your actual implementation right?
Ter
On Apr 4, 2007, at 1:58 AM, Brian Lewis wrote:

> 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());
>   }
> }
> _______________________________________________
> 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