[stringtemplate-interest] proposed "ignore newlines" template syntax

Sam Harwell sharwell at pixelminegames.com
Mon Apr 4 06:06:57 PDT 2011


After working to create some *very* large templates, Ter and I found that
the only true whitespace-related problem was the undesired introduction of
newline characters in the output. All other whitespace was straightforward
to control. The new option makes it especially easy to split larger
templates into multiple smaller ones. Also, we both felt that restricting
the feature to dropping only newline characters kept it in line with
StringTemplate's overall design simplicity.

In the templates I'm working on, I need to match the precise binary output
of a non-StringTemplate tool. The other tool is inconsistent in its use of
whitespace and single lines in the output ended up being 1000's of chars
long in the templates. This change alone made them completely manageable,
which I'm hoping is similar to what other users find.

Sam

-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Udo
Borkowski
Sent: Monday, April 04, 2011 2:14 AM
Cc: stringtemplate-interest List
Subject: Re: [stringtemplate-interest] proposed "ignore newlines" template
syntax

I like Jonathan's proposal and would prefer it over the <<< >>> syntax. 

The "character prefix"/"keyword prefix" approach makes it much easier to add
new options in the future, without the need to extend the syntax. 

It is also easier to remember. Assume if we introduce a new syntax for each
"feature" ( e.g. <<< >>> for 'ignore newlines', ''' . ''' for ignore all
whitespace, """ . """ for ignore indents.) I can already see myself
wondering which one meant what when I read old stuff. With the prefix syntax
(especially the "full option" variant) things are very obvious.

Udo


On 04.04.2011, at 06:38, Jonathan Buhacoff wrote:

> I think ... ::= <<< ... >>>  is ok.  But I'll throw a couple of other
ideas out there:
> 
> Characters at the beginning will be easy to extend later with other
options.
> 
> For example, ... ::= w<<...>>   might mean ignore whitespace.  Later you
might want ... ::= wgx<<...>>  to turn on ignore whitespace and two other
hypothetical options named "g" and "x". 
> 
> Or allow full option names enclosed by some other symbol:   ... ::=
[whitespace g xtra]<<. ... >>
> 
> Jonathan
> 
> 
> On Apr 4, 2011, at 2:09 AM, Terence Parr wrote:
> 
>> Hi. There is a proposal to create special syntax that allows arbitrary
formatting within a template that does not result in new lines in the
output. This is useful when you have a really complicated template with IFs
and such that needs to generate output all on the same line. Currently, this
can be quite challenging. There's no way to read a huge template on one
line. Sam Harwell and I came up with a potential solution: a new <<<...>>>
triple angle bracket template that ignores newlines unless you use <\n>
inside.
>> 
>> Here's a simple example:
>> 
>> ruleRef(rule,label,elementIndex,args,scope) ::= << 
>> <if(label)><label>=<endif><if(scope)><scope:delegateName()>.<endif><r
>> ule.name>(<args; separator=", ">);
>>>> 
>> 
>> it would probably be easier to read like this:
>> 
>> ruleRef(rule,label,elementIndex,args,scope) ::= <<< <if(label)> 
>> <label>= <endif> <if(scope)> <scope:delegateName()>.
>> <endif>
>> <rule.name>(<args; separator=", ">);
>>>>> 
>> 
>> come to think of it, perhaps it should also ignore whitespace so that I
could indent the conditionals:
>> 
>> ruleRef(rule,label,elementIndex,args,scope) ::= <<< <if(label)>
>> 	<label>=
>> <endif>
>> <if(scope)>
>> 	<scope:delegateName()>.
>> <endif>
>> <rule.name>(<args; separator=", ">);
>>>>> 
>> 
>> We while the syntax to be close, but still recognizable as different than
the usual <<...>>. I believe that there has been a proposal for special
characters at the start of the template and the addition of keyword but I
think a new template and closure syntax is better.
>> 
>> thoughts?
>> 
>> Thanks,
>> 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



More information about the stringtemplate-interest mailing list