[stringtemplate-interest] Fail on undefined property

Sam Harwell sharwell at pixelminegames.com
Fri Jul 31 12:48:27 PDT 2009


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>

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>

Sam

-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence
Parr
Sent: Friday, July 31, 2009 2:38 PM
To: Felix Dorner
Cc: stringtemplate-interest at antlr.org
Subject: Re: [stringtemplate-interest] Fail on undefined property


On Jul 31, 2009, at 2:04 AM, Felix Dorner wrote:

> Hi,
>
> I'm accessing properties of a Properties object in my template. I  
> need to fail generation if a requested property isn't defined (but  
> StringTemplate happily inserts the empty String in such cases.

Yeah, that's it's basic mode but it can be inconsistent about what  
throws an exception.

> What I did is to subclass Properties so that it throws a runtime  
> exception upon its get() method on undefined properties. However, I  
> see that you also make use of containsKey(), so I'd need to override  
> that too, and I'm starting to feel that my approach is probably not  
> the right way to go. Isn't there an option that tells StringTemplate  
> to fail if an attribute is not defined?

Is this these C# version?

You could override StringTemplate an alter its get attribute method.
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