[stringtemplate-interest] Fail on undefined property
John D. Mitchell
jdmitchell at gmail.com
Fri Jul 31 13:01:02 PDT 2009
Howdy,
I haven't followed this thread too closely but in terms of
optionality, one trick would be to add syntactic support for something
like:
<x?> or <x!>
or
<?x> or <!x>
The ? meaning you know it might not be there so do the current behavior.
The ! meaning that it must be there so bitch if it's not.
Given the backwards compatibility, it would seem like adding the !
would do the trick methinks (but I haven't done any ST stuff in awhile
so take that for what it's worth :-).
Have fun,
John
On Jul 31, 2009, at 12:52 , Terence Parr wrote:
>
> On Jul 31, 2009, at 12:48 PM, Sam Harwell wrote:
>
>> The problem is the same code path is used for evaluating conditional
>> expressions, where a missing attribute is "false". I believe when the
>> write method encounters an undefined property, it *should* throw an
>> exception. For example:
>>
>> Should not throw if x is undefined:
>>
>> <if(x)><x><endif>
>>
>> Should throw if x is undefined:
>>
>> <x>
>
> Well, it's very useful to evaluate to an empty string sometimes.
>
> Hi, <firstname> <lastname>
>
> if you only know the first name, we shouldn't have to gate every
> reference to other attributes to prevent an exception.
>
>> Note that we already do throw an exception in the following case if
>> x is
>> defined but has no member f. The behavior should be made consistent,
>> but
>> we have to be careful about informing people of the change since it's
>> absolutely a breaking change.
>>
>> <x.f>
>
> When I build the new version, I will make a consistent policy. Most
> likely there will be a choice that the user can set about strictness,
> turning on various bits in a set about what should throw an exception.
> T
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list