[stringtemplate-interest] need a null value for arguments?
Udo Borkowski
ub at abego-software.de
Tue Aug 2 00:41:23 PDT 2011
BTW: ST4 already has the null feature, sort of ;)
Just write:
main() ::= <<
<t(null)>
>>
and t will get a null (as the identifier null is not defined).
However you will get a warning logged to the console:
context [/main] 1:3 attribute null isn't defined
You can easily get rid of this warning by appending a parameter called "null" to your template:
main(null) ::= <<
<t(null)>
>>
This "null" parameter only needs to be add to the "root" template and can be used in any template call.
Even though this does work I still favor having a "real" null literal :)
Udo
On 01.08.2011, at 22:58, Sam Harwell wrote:
> 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/20110802/4906f779/attachment-0001.html
More information about the stringtemplate-interest
mailing list