[stringtemplate-interest] need a null value for arguments?

Udo Borkowski ub at abego-software.de
Mon Aug 1 13:03:59 PDT 2011


>> Also: to avoid confusion with the Java null maybe call the constant 'undefined'?
> 
> I was kind of thinking that it should be null because it has the same semantics as passing all in to add().

Actually this is not the case as you can see in the following test case. That's why I thought mixing "null" und "undefined" isn't such a good idea.

BTW: in the implementation the "undefined" literal should probably get the value ST.EMPTY_ATTR  rather than null.


public class UndefinedOrNullTest extends BaseTest {
	@Test
	public void testUndefinedParameter() throws Exception {
		writeFile(tmpdir, "t.stg", "t(s=\"world\") ::= <<\nHello <s>\n>>");
		String path = tmpdir + "t.stg";

		STGroup group = new STGroupFile(tmpdir + "/t.stg");
		ST st = group.getInstanceOf("t");
		String s = st.render();
		Assert.assertEquals("Hello world", s);
	}
	
	@Test
	public void testNullParameter() throws Exception {
		writeFile(tmpdir, "t.stg", "t(s=\"world\") ::= <<\nHello <s>\n>>");
		String path = tmpdir + "t.stg";

		STGroup group = new STGroupFile(tmpdir + "/t.stg");
		ST st = group.getInstanceOf("t");
		st.add("s", null);
		String s = st.render();
		Assert.assertEquals("Hello ", s);
	}
}


Udo

On 01.08.2011, at 21:33, Terence Parr wrote:

> 
> On Aug 1, 2011, at 7:10 AM, Udo Borkowski wrote:
> 
>> Not sure about the semantic of null.
>> 
>> E.g. assume you have this template
>> 
>> t(s="world") ::= "Hello <s>"
>> 
>> What will 
>> 
>> <t(null)>
>> 
>> render? 
>> 
>> a) "Hello " (i.e. same as <t("")>)
>> b) "Hello world" (i.e. same as <t()>)
> 
> I would assume it would render this one since the parameters missing.
> 
>> c) "Hello null" 
>> d) something else?
>> 
>> 
>> Also: to avoid confusion with the Java null maybe call the constant 'undefined'?
> 
> I was kind of thinking that it should be null because it has the same semantics as passing all in to add().
> 
> Ter
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110801/9b162166/attachment-0001.html 


More information about the stringtemplate-interest mailing list