[stringtemplate-interest] Output string lengths..
John Snyders
jjsnyders at rcn.com
Mon Dec 11 08:47:28 PST 2006
Now that we have the format option you could do
$d1;format("pad,20")$, $d2;format("pad,30")$
and let the render grab the width from the format name but this is ugly.
The need for pad is legitimate. The proposed solutions so far:
1) do it in the model by pre pading:
This pushes presentation into the model and is undesireable for that reason
2) do it in the model by other means such as pseudo properties (Ex:
$d1.pad20$):
Has all the disadvantages that ;format was intended to solve.
3) use format as is and encode the width into the format string:
It will work but as I said it is ugly
4) use chars function as I discribed in a previous message:
It works. Chars function could have other uses independent of this one. But
using
chars for padding is likely inefficent and the intent is not clear.
$chars(s1),chars(space40): { ch, sp | $ch;null={$sp$}$}$ is hard to
understand!
5) add pad option (Ex $d1;pad(20)$):
First a question. Option seems the right thing to me but is there some
wisdom about when to use the option mechanism and when to use the function
mechanism?
Pad option does no harm as far as I can see. It is also very clear about
what the intent is.
I wonder if it is just a special case of format and instead indicates that
options should be able to take additional parameters. I would expect pad to
behave in all respects like format in terms of how it applies to the
template. It should apply to attributes and the result of templates and the
null value but not separator. Wait this last part is not right. Pad is not
idempotent and format currently can call the renderer twice for the same
string. I said that this might be a bug and I still need to look into it. I
think pad would want to pad the whole result of a template expansion (even
after list iteration). Perhaps the format implementation is wrong here.
If format is changed so it is only called once per template, applies to the
whole template and options could have multiple arguments it might look like
this
$d1;format("pad",20)$
I started out agreeing with pad option but now I'm not sure.
-John
> -----Original Message-----
> From: stringtemplate-interest-bounces at antlr.org
> [mailto:stringtemplate-interest-bounces at antlr.org]On Behalf Of Terence
> Parr
> Sent: Saturday, December 09, 2006 4:24 PM
> To: StringTemplate
> Subject: Re: [stringtemplate-interest] Output string lengths..
>
>
> Without making pad an actual predefined option, it is hard to pass
> the 20 value to the renderer.
>
> Like wrap etc., is this something worth adding to ST?
>
> Ter
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list