[stringtemplate-interest] Additional attributes in template application?

Mark Wharton contact at moonbase.com.au
Sun Nov 4 02:59:49 PST 2007


Hello,

Amazing how writing an email about a problems helps you solve it!

  result := [ $Elements:{o$it$ElementSeed};separator=", "$ ];

Does the trick! $first$ and $last$ etc are probably not necessary.

Feeling a little silly for my first post...

Cheers,

Mark

On Sun, 04 Nov 2007 19:00:30 +0900, "Mark Wharton"
<contact at moonbase.com.au> said:
> Hello Hello,
> 
> A question about $first$ and $last$ attributes in template application.
> 
> I've implemented a subset of string template for one of my projects. 
> Template application is working (but not attribute operators). I added
> $first$, $last$, and $more$ attributes in template application for
> templates to properly handle end of list in code generation...
> 
> For example my template (source.st) includes the following:
> 
> GetElementFieldArray()
>   do
>     result := [ $Elements;separator=", "$ ]; -- seed array complement
>   end;
> 
> GetElementSeedArray()
>   do
>     result := [ $Elements:{o$it$ElementSeed$if(!last)$, $endif$}$ ];
>   end;
> 
> Elements is a multi-valued attribute with "EditBuffer" & "UndoBuffer".
> 
> ToString produces:
> 
> GetElementFieldArray()
>   do
>     result := [ EditBuffer, UndoBuffer ]; -- seed array complement
>   end;
> 
> GetElementSeedArray()
>   do
>     result := [ oEditBufferElementSeed, oUndoBufferElementSeed ];
>   end;
> 
> Is this really a good idea? Even though I'm using my own implementation,
> I don't want non standard elements if it can be helped. String template
> defines $it$, $i$ and $i0$. I believe $first$, $last$, $more$ are
> logical additions, however, I don't deny the thought that went
> into adding $it$, $i$ and $i0$ in the first place.
> 
> I've looked at the documentation for attribute operators but it was not
> obvious how to treat cases like the one I've described above.
> 
> Any help would be wonderful, thanks.
> 
> Cheers,
> 
> Mark
> 
> Mark Wharton
> + 8190 9834 2559
> contact at moonbase.com.au
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
Mark Wharton
+ 8190 9834 2559
contact at moonbase.com.au



More information about the stringtemplate-interest mailing list