<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><span class="Apple-style-span" style="font-size: medium;"><br></span></div></div></div></span></div></span></div><div><div>On Nov 8, 2009, at 10:40 AM, Terence Parr wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Verrrrrrry interesting. &nbsp;Perhaps this gives an opport. to format templates w/o messing up output.<div><br></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&lt;if(x)&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">foo</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&lt;endif&gt;</span></font></div><div><br></div><div>would give "foo\n" by default if x. &nbsp;It would give "" if !x. &nbsp;Wait, how to remove \n from after foo?</div><div><br></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&lt;if(x)&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">foo</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&lt;-endif&gt;</span></font></div><div><br></div><div>?? probably not.</div><div><br></div></div></blockquote><div><br></div><div><span class="Apple-style-span" style="font-size: 12px; "><div>You could remove the \n from after foo like this:</div><div><br></div><div>&lt;if(x)&gt;</div><div>foo&lt;empty-&gt; &nbsp; &nbsp;&lt;! where empty is an empty template named "empty" !&gt;</div><div>&lt;endif&gt;</div><div><br></div><div>or</div><div><br></div><div>&lt;if(x)&gt;</div><div>foo&lt;""-&gt; &nbsp; &lt;! empty string as literal empty template &nbsp;!&gt;</div><div>&lt;endif&gt;</div><div><br></div><div><br></div><div>Maybe &lt;""-&gt; looks rather ugly, &nbsp;but how nice can a representation of nothingness be? &nbsp;Maybe &lt;\\-&gt; is a little better, but I would expect a backslash out of that and not an empty string. &nbsp;Maybe \e meaning empty string could then be used as &lt;\e-&gt;. &nbsp; I like \e because it doesn't step on any existing standard that I know of. &nbsp;ANSI-C &nbsp;defines only \n \r \t \b \\ \? \' and \"</div><div><br></div></span></div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Let's use a real example where I have a huge single template line to obtain a single output line (it might wrap in your emailer:</div><div><br></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">public &lt;returnType()&gt;&nbsp;&lt;<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>&gt;(&lt;ruleDescriptor.parameterScope:parameterScope(scope=it)&gt;) throws&nbsp;RecognitionException \{ &lt;if(ruleDescriptor.hasReturnValue)&gt;return&nbsp;&lt;endif&gt;&lt;ruleDescriptor.grammar:delegateName()&gt;.&lt;<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>&gt;(&lt;ruleDescriptor.parameterScope.attributes:{a|&lt;<a href="http://a.name">a.name</a>&gt;}; separator=", "&gt;); \}}; separator="\n"&gt;<br></span></font><br></div><div>Here we have exprs and IF stuff and {...} stuff with separator option. &nbsp;What I'd like is to add some formatting:</div><div><br></div><div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">public &lt;returnType()&gt; &lt;<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>&gt;(</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&nbsp;&nbsp; &nbsp;&lt;ruleDescriptor.parameterScope:parameterScope(scope=it)&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">) throws RecognitionException&nbsp;{</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&nbsp;&nbsp; &nbsp;&lt;if(ruleDescriptor.hasReturnValue)&gt;return &lt;endif&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&nbsp;&nbsp; &nbsp;&lt;ruleDescriptor.grammar:delegateName()&gt;.&lt;<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>&gt;(</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;ruleDescriptor.parameterScope.attributes:{a|&lt;<a href="http://a.name">a.name</a>&gt;}; separator=", "&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">&nbsp;&nbsp; &nbsp;);</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">\}}; separator="\n"&gt;</span></font></div><div><br></div></div></div></blockquote><div><br></div><div>My attempt, this time trying &lt;\e-&gt; to see how it looks. &nbsp;Notice also the leading/trailing whitespace control on other tags:</div><div><br></div><div>public &lt;returnType()&gt; &lt;ruleDescriptor.name&gt;(&lt;\e-&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;-ruleDescriptor.parameterScope:parameterScope(scope=it)-&gt;<br>) throws RecognitionException {&lt;\e-&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;-if(ruleDescriptor.hasReturnValue)&gt;return &lt;endif-&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&lt;-ruleDescriptor.grammar:delegateName()&gt;.&lt;ruleDescriptor.name&gt;(&lt;\e-&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;-ruleDescriptor.parameterScope.attributes:{a|&lt;a.name&gt;};<br>separator=", "-&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;);&lt;\e-&gt;<br>\}}; separator="\n"&gt;</div><div><br></div><div>Or, if the rule for trailing whitespace control is eliminate all whitespace up to the next template tag or literal character (like what &lt;\\&gt; is currently supposed to do), then this specific example wouldn't need to use the leading whitespace controls (but they'd still be necessary for other situations):</div><div><br></div><div><div>public &lt;returnType()&gt; &lt;ruleDescriptor.name&gt;(&lt;\e-&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;ruleDescriptor.parameterScope:parameterScope(scope=it)-&gt;<br>) throws RecognitionException {&lt;\e-&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;if(ruleDescriptor.hasReturnValue)&gt;return &lt;endif-&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;ruleDescriptor.grammar:delegateName()&gt;.&lt;ruleDescriptor.name&gt;(&lt;\e-&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ruleDescriptor.parameterScope.attributes:{a|&lt;a.name&gt;};<br>separator=", "-&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;);&lt;\e-&gt;<br>\}}; separator="\n"&gt;</div><div><br></div></div><div><br></div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Or something like that. &nbsp;BUT, I don't want any newlines in output. I.e., I want newlines to format template itself not output. In 3.2.1 I added &lt;\\&gt; (though I think it's broken).</div><div><br></div><div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">public &lt;returnType()&gt; &lt;<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>&gt;(&lt;\\&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">&nbsp;&nbsp; &nbsp;&lt;ruleDescriptor.parameterScope:parameterScope(scope=it)&gt;&lt;\\&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">) throws RecognitionException&nbsp;{&lt;\\&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">&nbsp;&nbsp; &nbsp;&lt;if(ruleDescriptor.hasReturnValue)&gt;return &lt;endif&gt;&lt;\\&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">&nbsp;&nbsp; &nbsp;&lt;ruleDescriptor.grammar:delegateName()&gt;.&lt;<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>&gt;(&lt;\\&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;ruleDescriptor.parameterScope.attributes:{a|&lt;<a href="http://a.name">a.name</a>&gt;}; separator=", "&gt;&lt;\\&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">&nbsp;&nbsp; &nbsp;);&lt;\\&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">\}}; separator="\n"&gt;</span></font></div><div><font class="Apple-style-span" face="Monaco"><br></font></div></div><div>I guess that works. The &lt;\\&gt; would scarf \n followed by whitespace. &nbsp;Hmm....seems ok.</div><div><br></div><div>I like the '-' idea so we could indent IFs:</div><div><br></div><div>&lt;if(x)&gt;</div><div>&nbsp;&nbsp; &nbsp;&lt;-name&gt; &nbsp;&lt;! don't indent; I'm just formatting template !&gt;</div><div>&lt;endif&gt;</div><div><br></div><div>OTOH, that makes it harder to read templates. have to read carefully to figure out indentation.</div><div><br></div></div></div></blockquote><div><br></div><div>To me the hyphens kind of stand out, but even if they didn't, knowing that hyphens control whitespace that would be the first thing I look for if I have a whitespace issue.&nbsp;</div><div><br></div><div>here's the first example again using \e:</div><div><br></div><div><span class="Apple-style-span" style="font-size: 12px; "><div>&lt;if(x)&gt;</div><div>foo&lt;\e-&gt; &nbsp; &lt;! empty string as literal empty template, with trailing whitespace control &nbsp;!&gt;</div><div>&lt;endif&gt;</div><div><br></div></span></div><div><br></div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>If we wanted to use multi-line IF to mean single line we can do:</div><div><br></div><div>&lt;if(x)&gt;</div><div>foo&lt;\\&gt;</div><div>&lt;endif&gt;</div><div><br></div><div>yields foo if x.</div><div><br></div><div>Ter</div></div></div></blockquote></div><br></body></html>