[stringtemplate-interest] leading/trailing whitespace trimmed
Zenaan Harkness
zen at freedbms.net
Thu Apr 17 20:38:36 PDT 2008
>> # This produces almost the same result as 2) above, except there are
>> # extra space characters lurking around (just after the first open
>> # brace, and just before the last open brace):
>> public String getParam () {
>>
>> return _param != null ? _param
>> : _returns != null ? _returns
>> : null;
>>
>> }
>
> Yeah, that is ugly I guess... I think you need to think about this a
> different way. A template specifies content but the surrounding template
> specifies a whitespace around that template. Instead of your
>
> public <a.type> get<a.name> () {<if(a.customGetter)>
>
> do this
>
> public <a.type> get<a.name> () {
> <if(a.customGetter)>
>
> and then all of a sudden you get exactly what you want and it looks great.
The reason I don't do it that way (yes it would work for multi-line
getter), is that I wanted to have the default be a single-line getter,
as in, the template producing something like:
public String getInfo () {return _info;}
and only if there's a custom getter do I go to multi line, and then only
if the custom getter _needs_ to go multi line. This is why I went to
such lengths of experimentation :)
So, they way I have it, the default getter and custom getters are one
line, and multi-line custom getters are multi line.
Perhaps I'm being too demanding. But it does work, if a little less than
ideally pretty in the templates.
>> 4) ----
>> # So, on to solution 4), where I take advantage of the first and
>> # last \n getting consumed, and have my template like so:
>> getBody(a) ::= <<
>> <\n> return _param != null ? _param
>> : _returns != null ? _returns
>> : null;<\n>
>>>>
>>
>> # Finally, I have produced the result, character for character,
>> # that I wanted, albeit with a template that's a bit ugly:
>> public String getParam () {
>> return _param != null ? _param
>> : _returns != null ? _returns
>> : null;
>> }
>
> That also works but is not as clean as what I just mentioned.
>
>> So in conclusion, there are 5 ways to get the job done, 3 of which
>> simply don't work, and two of which work.
>
> I only use one way and it seems to work great ;)
>
> :)
Absolutely.
I am totally stoked with what I am achieving with ST. Not only is it
possible to do what I want, but I can jig the templates to produce
some flexibility in output too (single vs multi line getters for example
:)
Thank you ____________this_____________ much for ST.
As a coder, it's like I'm a kid in a lolly warehouse.
Now, if we can just get built in template existence checking ... :)
(see earlier email, ala:
<ifexists(TEMPLATE_NAME_TO_CHECK)><(TEMPLATE_NAME_WILL_RUN)()><endif>
Seems like a simple tamplate_name->template lookup table...
Much more efficient than the manual parsing I have to do in my code to
get _only a limited set of template names_ to be customizers...
)
Best regards
Zen
--
Homepage: www.SoulSound.net -- Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.
More information about the stringtemplate-interest
mailing list