[stringtemplate-interest] Generating big documents

Terence Parr parrt at cs.usfca.edu
Wed Dec 27 17:01:07 PST 2006


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



More information about the stringtemplate-interest mailing list