[stringtemplate-interest] Problem in multivalued attribute handling?

Praki Prakash praki.prakash at gmail.com
Sat Jul 8 12:11:18 PDT 2006


Hi Colin,

Thanks for your response.

I suspect as much that the code is written as "if attr:" which would cause
all numerical zeros to evaluate to false. From my perspective, this is a
terrible bug making ST completely unusable. My model is full of
multi-dimensional data and quite a bit of it is 0. Unfortunately, the
workaround you suggest is not really usable as I need numerical data to do
computations and having to generate a stringified version is too much work
and inelegant.

I tried to hack the code a bit. I found a method, convertAnythingToList and
tried to alter the way it checks attributes. My intuition proved to be wrong
and it didn't fix the issue. I suspect there is more code elsewhere that
needs change. Unfortunately, I don't have time to look into this and have
had to suspend the use of StringTemplate in project for now. If you come up
with patches, please post :)

Thanks,
Praki

On 7/7/06, Colin Bean <ccbean at gmail.com> wrote:
>
> Hi Praki,
>
> I noticed a similar issue recently; I hadn't gotten around to looking
> at it in depth (I also hadn't verified it in 2.2 yet, but sounds like
> its still there).  As far as I know, PyST won't render any attribute
> (that's passed as an int or float) with a value of zero.  I haven't
> looked at the source code, but I assume that somewhere there's a
> conditional that checks for the value/existence of an attribute, then
> checks it in such a way that a 0 evaluates to false and ST doesn't
> think that the attribute exists.  If you're passing integer values
> into a template, casting them to a string before passing them causes
> all zero values to render correctly (that's the workaround I've been
> using for now, anyway).
>
> So I haven't verified if this is expected behavior or if this is
> unique to the python implementation, but I've noticed the same
> behavior.   I'm on vacation this weekend, so I don't have any ST code
> near at hand, but when I get back I'll verify the above assumptions
> and report back ;)
>
> Anyone else?  Is this a feature or a bug?
>
> Thanks,
> -Colin
>
> On 7/6/06, Praki Prakash <praki.prakash at gmail.com> wrote:
> > Hi,
> >
> > While using the Python version of StringTemplate, I noticed that my
> > multivalued attribute was missing all the zero values. The following
> snippet
> > demonstrates the problem. I am using version 2.2. Is this a bug? Is
> there a
> > workaround?
> >
> > >>> import stringtemplate
> > >>> st=stringtemplate.StringTemplate("$[0,1,0,1]:{$it$}$")
> > >>> print st
> > 11
> >
> > Thanks
> > Praki
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060708/bcdedb39/attachment.html


More information about the stringtemplate-interest mailing list