[stringtemplate-interest] Additional attributes in template application?
Mark Wharton
contact at moonbase.com.au
Sun Nov 4 02:00:30 PST 2007
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
More information about the stringtemplate-interest
mailing list