[stringtemplate-interest] "".."" won't work

Terence Parr parrt at cs.usfca.edu
Wed Apr 6 16:04:13 PDT 2011


yeah,I think it's okay to ignore indents. ok done. Made a few unit tests and pushed. e.g.,

	@Test public void testIgnoreIndentInIF() throws Exception {
		String template =
			"t(x) ::= <%\n" +
			"	<if(x)>\n" +
			"		foo\n" +
			"	<endif>\n" +
			"	<x>\n" +
			"%>\n";
		STGroup g = new STGroupString(template);
		ST st = g.getInstanceOf("t");
		st.add("x", 99);
		String expected = "foo99";
		String result = st.render();
		assertEquals(expected, result);
	}

Ter
On Apr 6, 2011, at 10:41 AM, Sam Harwell wrote:

> Looking through the ANTLR templates, do you see any cases where it's an
> issue to throw out both NEWLINE and INDENT tokens coming from STLexer?
> INDENT is any leading whitespace on a line.
> 
> I'm looking at my other large codegen project and I can't see any place
> where I need that indent. All the "indented blocks" in my code are indented
> within a regular <<...>> BIGSTRING.
> 
> Sam
> 
> -----Original Message-----
> From: stringtemplate-interest-bounces at antlr.org
> [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence Parr
> Sent: Wednesday, April 06, 2011 12:36 PM
> To: stringtemplate-interest List
> Subject: Re: [stringtemplate-interest] "".."" won't work
> 
> Yeah,That is what I was thinking before. Ignoring indentation, particularly
> in front of conditionals seems reasonable. On the other hand what about
> indentation in front of text?
> 
> t() ::= <%
> 	start
> 	<if(x)>
> 		<x>
> 		foo
> 	<endif>
> 	end
> %>
> 
> should all that be ignored as equivalent to:
> 
> t() ::= <%
> start
> <if(x)>
> <x>
> foo
> endif>
> end
> %>
> 
> I like the idea of throwing away indentation in front of conditionals; not
> sure about in front of text, but probably should for consistency.
> 
> T
> 
> On Apr 5, 2011, at 9:24 PM, Sam Harwell wrote:
> 
>> I still don't see how <% %> would lead to implementation or usage
> problems. Can anyone give a concrete example where it breaks?
>> 
>> The comments suggestion is completely impractical for the size templates I
> work with, even with syntax highlighting.
>> 
>> That said, I just realized that it might make sense for <% %> to drop
> INDENT tokens as well, for the following reasons:
>> 
>> .         Indentation doesn't make sense for a single-line token.
>> .         If someone wanted to insert whitespace in the middle of a line
> in a single-line template, it wouldn't be at the beginning of a line.
>> 
>> Sam
>> 
>> From: stringtemplate-interest-bounces at antlr.org 
>> [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Udo 
>> Borkowski
>> Sent: Tuesday, April 05, 2011 10:10 PM
>> To: Terence Parr
>> Cc: stringtemplate-interest List
>> Subject: Re: [stringtemplate-interest] "".."" won't work
>> 
>> 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><ru
>> le.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