[stringtemplate-interest] Generating big documents
Adam Bennett
adamb at videx.com
Thu Dec 28 08:47:45 PST 2006
So is the said piece of code the only problem or are there other issues
with using Iterators more lazily. For instance the Iterator can only be
evaluated once in the case of a ResultSet being streamed from the
database (because you must re-execute the query if you want to iterate
over the results again). This makes it a stateful attribute and so only
one template could reference it and even then it could only be
referenced once.
Terence Parr wrote:
> On Dec 27, 2006, at 4:45 PM, John Snyders wrote:
>
>
>> I would have thought this would work but now I can see it doesn't.
>>
>> The problem is in ASTExpr.applyListOfAlternatingTemplates. It is
>> trying to gather up the results of the first template. I think the
>> reason it is doing this is because it is possible to nest the
>> templates. The example from the documentation is
>> $names:{$it$}:{
>> $it$
>> }$
>> First all the names are iterated over and a result list of string
>> templates with arguments initialized is returned. Then the list of
>> string templates is evaluated. In the first loop the values are
>> it=0, it=1, it=2... in the second loop the values are it=<b>0</b>,
>> it=<b>1</b>, ...
>> I was surprised to see it done this way. I think it is very
>> inefficient and clearly will not work for what you are trying to
>> do. It would be nice if it could go depth first rather than breadth
>> first. If not at least notice that there is no nested template to
>> iterate in your case.
>>
>> Can someone comment on why nested iterations are handled this way?
>>
>
> Yep, it's not super common and the implementation is easier to handle
> one "map" (colon operator) at a time. Stuff is more uniform.
>
> $data:{$i$ == $it$\n}$ should work...if you do toString on that, it
> should write as it evaluates. I'd be surprised if I created a list
> first and then printed the list.
>
>
>> Note that $data$ does not have the same problem. The values are
>> continually written to the DummyWriter. But this is not very
>> helpful. A named template will also not work ex: $data:line()$
>>
>
> Wow...i'm a dummy I guess. crap.
>
>
>> I think your use case is an interesting and important one. Not
>> sure if this issue can be resolved and there may be more issues
>> beyond that.
>>
>>
>
> Ter
>
> _______________________________________________
> 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/20061228/18965a5d/attachment.html
More information about the stringtemplate-interest
mailing list