[stringtemplate-interest] formal arg checking
Terence Parr
parrt at cs.usfca.edu
Sun Apr 29 15:39:10 PDT 2007
On Apr 26, 2007, at 12:09 PM, Nate wrote:
> I assume you are proposing this...
>
> $if (errorMessage)$
> $table(emptyMessage=errorMessage)$
> $else$
> $table(emptyMessage="The list is empty.")$
> $endif$
>
> While this would solve my specific scenario, formal argument
> checking is
> still flawed. I should be able to use undefined attributes when
> applying
> a template, like this...
>
> $table(emptyMessage={$errorMessage; null="The list is empty."$})$
>
> When "errorMessage" is not defined, that code currently throws an
> error
> saying that the attribute "errorMessage" is not a valid formal
> argument
> for the "table" template.
Is error message defined anywhere in the surrounding context? that
is, in an enclosing template? If not, you cannot reference an
undefined attribute just like in a programming language. If I were
you, I would just add errorMessage to the template that invokes table
and you problem disappears.
> Also, the workaround to use an IF statement is not very elegant for
> more
> complex scenarios because it duplicates the template call. Eg...
>
> $if (errorMessage)$
> $table(
> emptyMessage=errorMessage,
> rows={
> Lots of HTML here.
> }
> )$
> $else$
> $table(
> emptyMessage="The list is empty.",
> rows={
> Lots of HTML here.
> }
> )$
> $endif$
>
> Hope you have fun on your trip!
Well, yes, but I ended up getting a cold. was at a party at my
brother's house with 30 screaming 10-year-old boys. As Jim Idle
says, the probability that one of them has a nasty virus is 1. ;) The
probability that they will do their best to give it to you is nearly
1. ;)
Ter
More information about the stringtemplate-interest
mailing list