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

Terence Parr parrt at cs.usfca.edu
Sun Apr 3 16:09:00 PDT 2011


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><rule.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




More information about the stringtemplate-interest mailing list