[stringtemplate-interest] summarizing white space and indentation
Jonathan Buhacoff
jonathan at buhacoff.net
Mon Nov 9 10:03:07 PST 2009
Just a couple of comments:
Sent from my iPhone
On Nov 8, 2009, at 9:49 PM, Zenaan Harkness <zen at freedbms.net> wrote:
> 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.
I agree, removing all whitespace until next non-whitespace char is a
clearer rule.
> ...
>> 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.
>
I considered <-> but it's ambiguous about which direction it controls.
Consider :
Select * from <->
Sometable where...
It's not clear if the intent is to remove the space after "from" or to
remove the newline before "sometable". It certainly shouldn't be both,
that would cause an SQL syntax error.
Select * from <\e->
sometable where...
This way (doesnt have to be \e) it's clearer the intent is to remove
the trailing newline and preserve the leading space
> ...
>>> 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.
> _______________________________________________
> 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