[stringtemplate-interest] need for null test

Collin Fagan collin.fagan at gmail.com
Mon Jan 17 19:13:18 PST 2011


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> 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:
>
> >
> > Hi,
> >
> > we use an enhanced version of ST3 for xml rendering and while ST4 makes
> > most of our enhancements obsolete (in particular by supporting adaptors),
> > one crucial omission remains:
> >
> > In order to render Boolean types declared as "xsd:boolean nillable=true"
> in an xsd,
> > we need to distinguish between false and null values, as the output has
> to
> > be either
> > <tag>false</tag> or <tag nil="true"/>, respectively.
> >
> > I couldn't find any way to express this logic using ST4's if statement
> > given a Boolean attribute, as false and null both evaluate to false.
> >
> > If that kind of logic can be expressed in ST4, I'd really appreciate any
> hint
> > on how its done; otherwise I think that a "test for null"-expression
> should be added
> > to the language, e.g., "if (?foo) ... "
> >
> >
> >
> > Regards,
> > Oliver
> >
> >
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
> _______________________________________________
> 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/20110117/6397fd2f/attachment.html 


More information about the stringtemplate-interest mailing list