[stringtemplate-interest] "".."" won't work
Terence Parr
parrt at cs.usfca.edu
Wed Apr 6 10:34:06 PDT 2011
well,In that case we already have the <\\> "insert but ignore \n" feature. :)
TerOn Apr 5, 2011, at 8:09 PM, Udo Borkowski wrote:
> Let's get back to the original issue:
> we want to make templates more readable that currently packed in one line (to avoid newline output):
>> Here's a simple example:
>>
>> ruleRef(rule,label,elementIndex,args,scope) ::= <<
>> <if(label)><label>=<endif><if(scope)><scope:delegateName()>.<endif><
>> rule.name
>> >(<args; separator=", ">);
>> >>
>>
>>
> Do we really need a new feature to achieve this?
> What about using stuff already implemented to improve readablity?
>
> E.g. comments can be used to insert linebreaks that are visible in the template but not rendered:
>
> ruleRef(rule,label,elementIndex,args,scope) ::= <<<!
> !><if(label)><!
> !><label>=<!
> !><endif><!
> !><if(scope)><!
> !><scope:delegateName()>.<!
> !><endif><!
> !><
> rule.name
> >(<args; separator=", ">);
> >>
>
>
> With a proper syntax highlighting (which makes comments very "light") it becomes even more readable:
>
> ruleRef(rule,label,elementIndex,args,scope) ::= <<
> <!
> !>
> <if(label)>
> <!
> !>
> <label>=
> <!
> !>
> <endif>
> <!
> !>
> <if(scope)>
> <!
> !>
> <scope:delegateName()>.
> <!
> !>
> <endif>
> <!
> !>
> <rule.name
> >(<args; separator=", ">);
> >>
>
>
> These comments can even be used to do indents, improving the readability again:
>
> ruleRef(rule,label,elementIndex,args,scope) ::= <<
> <!
> !>
> <if(label)>
> <!
> !>
> <label>=
> <!
> !>
> <endif>
> <!
> !>
> <if(scope)>
> <!
> !>
> <scope:delegateName()>.
> <!
> !>
> <endif>
> <!
> !>
> <rule.name
> >(<args; separator=", ">);
> >>
>
> This final example looks very readable to me, even more readable than the template we would write with the suggested "newline eating" syntax:
>> ruleRef(rule,label,elementIndex,args,scope) ::= <<<
>> <if(label)>
>> <label>=
>> <endif>
>> <if(scope)>
>> <scope:delegateName()>.
>> <endif>
>> <
>> rule.name
>> >(<args; separator=", ">);
>> >>>
>>
> Of cause this "comment formatting" involves a little more typing, but this can easily handled by any good editor (Ter: "... emacs is your friend ;)").
>
> With this idea in mind, do we really need to add this "newline eating" feature?
>
> To me the benefit does not look that big. As I have not yet written any real long "one liners" I may not be the right person to judge this, so what do others think?
>
> Implementing the "line eating" feature has quite its difficulties, as we noticed already. I have no doubt these issues can be solved, however I assume "StringTemplate's overall design simplicity" (Sam Harwell) will be bigger without it.
>
>
> Udo
>
> On 05.04.2011, at 18:31, Terence Parr wrote:
>
>> yeah it was hassle flipping << >> to <% %> in Java.stg templates, though I'd need to insert [..] or whatever just the same. still open for debate :)
>> T
>> On Apr 5, 2011, at 5:03 AM, Udo Borkowski wrote:
>>
>>> Following this thread makes me think if extending the syntax through new template delimiters ("", """, <% or whatsoever) is really a good idea.
>>>
>>> I assume we run into less problems (conflict with old syntax, escape issues etc.) with just sticking to the old ones ("…" and <<…>>) and just add the optional "[…]" template prefix, as already suggested earlier.
>>>
>>> t() ::= […]<<
>>> .
>>> .
>>> .
>>> >>
>>>
>>> Udo
>>>
>>>
>>>
>>> On 05.04.2011, at 06:15, Terence Parr wrote:
>>>
>>>> oh right. might work.
>>>> Ter
>>>> On Apr 4, 2011, at 8:06 PM, Sam Harwell wrote:
>>>>
>>>>> If you chose % as your delimiter, it would still be fine. The template starts at <% and ends at %>.
>>>>>
>>>>> <%%x%%>
>>>>>
>>>>> Sam
>>>>>
>>>>> From: Collin Fagan [mailto:collin.fagan at gmail.com]
>>>>> Sent: Monday, April 04, 2011 9:29 PM
>>>>> To: Sam Harwell
>>>>> Cc: Terence Parr; stringtemplate-interest List
>>>>> Subject: Re: [stringtemplate-interest] "".."" won't work
>>>>>
>>>>> I have no problem with <%...%> but that eliminates one character available as a valid delimiters right?
>>>>>
>>>>> I can't set the starting and ending delimiters to '%' and have %%...%% can I?
>>>>>
>>>>> Collin
>>>>>
>>>>> On Mon, Apr 4, 2011 at 8:39 PM, Sam Harwell <sharwell at pixelminegames.com> wrote:
>>>>> If you want to emit the literal %> in the output, you can write it as %\>,
>>>>> using the existing escape sequence without breaking anything.
>>>>>
>>>>> Sam
>>>>>
>>>>> -----Original Message-----
>>>>> From: stringtemplate-interest-bounces at antlr.org
>>>>> [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence Parr
>>>>> Sent: Monday, April 04, 2011 8:07 PM
>>>>> To: stringtemplate-interest List
>>>>> Subject: Re: [stringtemplate-interest] "".."" won't work
>>>>>
>>>>>
>>>>> On Apr 4, 2011, at 6:05 PM, Sam Harwell wrote:
>>>>>
>>>>> > I guess with <%..%>, the escape character is still \>?
>>>>> >
>>>>> > This should work fine.
>>>>>
>>>>> Well, shouldn't need any escape really...should be \%?
>>>>> Ter
>>>>> _______________________________________________
>>>>> stringtemplate-interest mailing list
>>>>> stringtemplate-interest at antlr.org
>>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>>>
>>>>> _______________________________________________
>>>>> stringtemplate-interest mailing list
>>>>> stringtemplate-interest at antlr.org
>>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>>>
>>>>
>>>> _______________________________________________
>>>> stringtemplate-interest mailing list
>>>> stringtemplate-interest at antlr.org
>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>>
>>
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list