[stringtemplate-interest] summarizing white space and indentation

Zenaan Harkness zen at freedbms.net
Sun Nov 8 21:49:30 PST 2009


On Mon, Nov 09, 2009 at 12:48:10PM +1100, Zenaan Harkness wrote:
> On Sun, Nov 08, 2009 at 12:59:43PM -0800, Jonathan Buhacoff wrote:
> >
> > On Nov 8, 2009, at 10:40 AM, Terence Parr wrote:
> >
> >> Verrrrrrry interesting.  Perhaps this gives an opport. to format  
> >> templates w/o messing up output.
...
> >> <if(x)>
> >> foo
> >> <-endif>
> 
> Yes. Looks very clean. Aligns with an existing syntax that Jonathan
> raised. Perfect.
> 
> Only thing is, you're still assuming removing initial \n.
> So instead perhaps use:
> 
>    <if(x)->
>    foo
>    <-endif>
> 
> Of course, if we wanted to be really strict here, then it might be:
> 
>    <-if(x)>
>    foo
>    <endif->
> 
> with the question arising, does the '-' be the syntax that removes
> all whitespace, or just \n. I suggest that anything other than "all
> whitespace between this point and the next bit of non-whitespace is
> removed" would be confusing.
...
> Great stuff.

> > You could remove the \n from after foo like this:
> >
> > <if(x)>
> > foo<empty->    <! where empty is an empty template named "empty" !>
> > <endif>
> >
> > or
...
> How about just <> and <->, for completely-empty template (if ever
> needed) and for white-space-removing empty template, respectively?
> 
> Clean as it gets.

...
> > My attempt, this time trying <\e-> to see how it looks.  Notice also the 
> > leading/trailing whitespace control on other tags:
> >
> > public <returnType()> <ruleDescriptor.name>(<\e->
> >     <-ruleDescriptor.parameterScope:parameterScope(scope=it)->
> 
> Looking at the above two lines, if the '-' prefixing ruleDescriptor
> removes "all whitespace", then surely the '<\e->' (or <-> or whatever)
> is not necessary at all ??

Running with the "cleanest syntax is a single character innocuously
placed" idea, you could if you really wanted do '-' removes one
whitespace character, and '=' removes as many as found, rendering your
example above as:


public <returnType()> <ruleDescriptor.name>(
   <-ruleDescriptor.parameterScope:parameterScope(scope=it)->

Hows that sound?


> >> I guess that works. The <\\> would scarf \n followed by whitespace.   
> >> Hmm....seems ok.
> >>
> >> I like the '-' idea so we could indent IFs:
> >>
> >> <if(x)>
> >>     <-name>  <! don't indent; I'm just formatting template !>
> >> <endif>
> >>
> >> OTOH, that makes it harder to read templates. have to read carefully  
> >> to figure out indentation.
> 
> I think what you need is any of the following:
> 
> <if(x)>
>     <-name>
> <-endif>
...


or:

<if(x)>
    <=name>
<-endif>

<if(x)>
    <=name->
<endif>

<if(x)=>
    <name>
<-endif>

Of course, where there is only one whitespace character, it's a moot
point. But where there is more than one whitespace character, and we
only want to remove the first, then '-' becomes quite useful.

best
zen


-- 
Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.


More information about the stringtemplate-interest mailing list