<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. 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;"><if(x)></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;"><endif></span></font></div><div><br></div><div>would give "foo\n" by default if x. It would give "" if !x. 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;"><if(x)></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;"><-endif></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><if(x)></div><div>foo<empty-> <! where empty is an empty template named "empty" !></div><div><endif></div><div><br></div><div>or</div><div><br></div><div><if(x)></div><div>foo<""-> <! empty string as literal empty template !></div><div><endif></div><div><br></div><div><br></div><div>Maybe <""-> looks rather ugly, but how nice can a representation of nothingness be? Maybe <\\-> is a little better, but I would expect a backslash out of that and not an empty string. Maybe \e meaning empty string could then be used as <\e->. I like \e because it doesn't step on any existing standard that I know of. ANSI-C 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 <returnType()> <<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>>(<ruleDescriptor.parameterScope:parameterScope(scope=it)>) throws RecognitionException \{ <if(ruleDescriptor.hasReturnValue)>return <endif><ruleDescriptor.grammar:delegateName()>.<<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>>(<ruleDescriptor.parameterScope.attributes:{a|<<a href="http://a.name">a.name</a>>}; separator=", ">); \}}; separator="\n"><br></span></font><br></div><div>Here we have exprs and IF stuff and {...} stuff with separator option. 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 <returnType()> <<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>>(</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;"> <ruleDescriptor.parameterScope:parameterScope(scope=it)></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">) throws RecognitionException {</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;"> <if(ruleDescriptor.hasReturnValue)>return <endif></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;"> <ruleDescriptor.grammar:delegateName()>.<<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>>(</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;"> <ruleDescriptor.parameterScope.attributes:{a|<<a href="http://a.name">a.name</a>>}; separator=", "></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;"> );</span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px;">\}}; separator="\n"></span></font></div><div><br></div></div></div></blockquote><div><br></div><div>My attempt, this time trying <\e-> to see how it looks. Notice also the leading/trailing whitespace control on other tags:</div><div><br></div><div>public <returnType()> <ruleDescriptor.name>(<\e-><br> <-ruleDescriptor.parameterScope:parameterScope(scope=it)-><br>) throws RecognitionException {<\e-><br> <-if(ruleDescriptor.hasReturnValue)>return <endif-><br> <-ruleDescriptor.grammar:delegateName()>.<ruleDescriptor.name>(<\e-><br> <-ruleDescriptor.parameterScope.attributes:{a|<a.name>};<br>separator=", "-><br> );<\e-><br>\}}; separator="\n"></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 <\\> 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 <returnType()> <ruleDescriptor.name>(<\e-><br> <ruleDescriptor.parameterScope:parameterScope(scope=it)-><br>) throws RecognitionException {<\e-><br> <if(ruleDescriptor.hasReturnValue)>return <endif-><br> <ruleDescriptor.grammar:delegateName()>.<ruleDescriptor.name>(<\e-><br> <ruleDescriptor.parameterScope.attributes:{a|<a.name>};<br>separator=", "-><br> );<\e-><br>\}}; separator="\n"></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. 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 <\\> (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 <returnType()> <<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>>(<\\></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; "> <ruleDescriptor.parameterScope:parameterScope(scope=it)><\\></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">) throws RecognitionException {<\\></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; "> <if(ruleDescriptor.hasReturnValue)>return <endif><\\></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; "> <ruleDescriptor.grammar:delegateName()>.<<a href="http://ruleDescriptor.name">ruleDescriptor.name</a>>(<\\></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; "> <ruleDescriptor.parameterScope.attributes:{a|<<a href="http://a.name">a.name</a>>}; separator=", "><\\></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; "> );<\\></span></font></div><div><font class="Apple-style-span" face="Monaco" size="4"><span class="Apple-style-span" style="font-size: 16px; ">\}}; separator="\n"></span></font></div><div><font class="Apple-style-span" face="Monaco"><br></font></div></div><div>I guess that works. The <\\> would scarf \n followed by whitespace. Hmm....seems ok.</div><div><br></div><div>I like the '-' idea so we could indent IFs:</div><div><br></div><div><if(x)></div><div> <-name> <! don't indent; I'm just formatting template !></div><div><endif></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. </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><if(x)></div><div>foo<\e-> <! empty string as literal empty template, with trailing whitespace control !></div><div><endif></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><if(x)></div><div>foo<\\></div><div><endif></div><div><br></div><div>yields foo if x.</div><div><br></div><div>Ter</div></div></div></blockquote></div><br></body></html>