[stringtemplate-interest] need for null test

Oliver Flege o.flege at market-maker.de
Tue Jan 18 01:35:23 PST 2011


Hi,

thanks for suggesting the map approach (I never used literal maps before).
My group file now looks like this:

notFalse ::= ["false":"true"]"

tag(name,value) ::= <<"
$if(value || notFalse.(value))$<$name$>$value$</$name$>$else$<$name$ nil=\"true\"/>$endif$
>>

A user's template calling tag("foo", model.x.y)
will now result in syntactically correct markup.

The only thing I don't like is that notFalse.(value) will always be evaluated
by the Interpreter, so it creates a MapModelAdaptor, a StringWriter etc.
An language-supported null test would be a lot faster, I suppose.

Regards,
 Oliver



> I have experimented with maps in the past for null detection.
> 
> I built this as a general purpose map:
> 
> isFalse ::= ["false":"true"]
> 
> It returns true if the value is false, and null otherwise.
> 
> Then I use it in 'if statements'.
> 
> main(nullValue, falseValue) ::= <<
> 
> $if(*isFalse*.(falseValue))$
>     falseValue value is false;
> $endif$
> 
> $if(*!isFalse*.(nullValue))$
>     nullValue is NOT false;
> $endif$
> 
>>>
> 
> I try hard to avoid needing to tell the difference between null and false, but I can see you have no choice.
> 
> I hope this helps.
> 
> Collin
> 
> 
> On Mon, Jan 17, 2011 at 11:22 AM, Terence Parr <parrt at cs.usfca.edu <mailto:parrt at cs.usfca.edu>> wrote:
> 
>     try a map
> 
>     m ::= [ "true" : ..., "false":"<tag>false</tag>", default: "<tag nil=\"true\"/>"]
> 
>     then $m.(yourTagValue)$
> 
>     If that works, lemme know. i'll add to faq.
> 
>     Ter
>     On Jan 17, 2011, at 1:30 AM, Oliver Flege wrote:
> 


More information about the stringtemplate-interest mailing list