[stringtemplate-interest] null vs missing vs empty vs nonexistent

Terence Parr parrt at cs.usfca.edu
Thu Oct 15 16:14:56 PDT 2009


On Oct 15, 2009, at 2:25 PM, Graham Wideman wrote:

>
> At 10/15/2009 01:56 PM, Terence Parr wrote:
>> was thinking about that but figured it'd confuse. we have <if(!foo) 
>> foo
>> is missing<endif> anyway.
>
> ...though ! appears to have two problems for detecting the missing  
> case: it doesn't distinguish between FALSE and null (and missing if  
> missing is legal here),

oh crap.  I guess ! would return false if missing or null. Ah. right.  
I just built this:

     protected boolean testAttributeTrue(Object a) {
         if ( a==null ) return false;
         if ( a==MISSING_ATTR ) return false;
	...
     }

> and docs I think probably aren't clear on whether the missing case  
> is legal and treated like null, or should cause error.

Is it ok if missing and null yield false?

> Generally I think if you establish missing as a concept distinct  
> from null, then to minimizing confusion means that everywhere those  
> concepts arise they should get distinct treatment (eg: parallel  
> options in render).

True. very confusing.

> This of course runs into trouble applying boolean operators to what  
> is now becoming a 4-value situation: true-val/false-val/null/missing  
> --> true/false/maybe-error.
>
> :-(

ha! and yes: frown face.

> No time as good as a new version to take a stand though!
>
> (BTW, are you really saying there are also empty and nonexistant  
> cases?)

Empty is like "" and nonexistent/missing is literally nothing.

Crap. BTW, the ST impl code is simple until we deal with this  
concept. :(

Ok, reason this came up was

http://www.antlr.org/pipermail/stringtemplate-interest/2009-July/002020.html

<names:{n | <if(n.cool)><n><endif>}; separator=",">

Previous to 3.2.1 that yielded , , , , , type output if all names are  
uncool.  Definitely not what we want, right?  Well, we could argue  
that the filtering should be done in the model. all elements get a  
separator.

Next, what does {} mean as a template?  Is that empty string or  
missing?  what would this generate?

<names: {}; separator=", ">

It gives either empty string, missing, or ", , , , , , "

Grrr...ok, i'm not liking this.  I think I was only half right today.  
We should allow null-valued attributes like

st.add("name", null);

but let's make null mean same thing as missing.  I am thinking i made  
a mistake adding this to ST 3.2.1.

So even for any null values in a list, <names:{...}; separator=", ">  
yields a separator.

Ok, let me try this new version out in my unit tests.

Ter


More information about the stringtemplate-interest mailing list