[stringtemplate-interest] need a null value for arguments?
Sam Harwell
sharwell at pixelminegames.com
Mon Aug 1 13:58:54 PDT 2011
Adding "undefined" seems pointless, since you can already get that by simply
omitting an argument.
Due to the following expression, it seems reasonable to add a null constant
with the value null:
<t; null="stuff">
Sam
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Udo
Borkowski
Sent: Monday, August 01, 2011 3:04 PM
To: Terence Parr
Cc: stringtemplate-interest List
Subject: Re: [stringtemplate-interest] need a null value for arguments?
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/8e494b83/attachment-0001.html
More information about the stringtemplate-interest
mailing list