eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

Spacing around operators #99

Closed lucaswerkmeister closed 9 years ago

lucaswerkmeister commented 9 years ago

From the let expressions sample:

dist = (x ^ 2 + y ^ 2) ^ 0.5)
Point(x / dist, y / dist)

That seems a bit… excessive. Perhaps we should add an option to omit the spaces if both operands are atoms.

lucaswerkmeister commented 9 years ago

“Perhaps” here having the meaning of “I’ve been aware of this problem for a while, and didn’t want to care about it, but I’ve reached the point where I probably can’t ignore it any longer, and any “yes please” feedback will make me do this change.”

gavinking commented 9 years ago

Do it :)

Sent from my iPhone

On 30 Oct 2014, at 9:49 pm, Lucas Werkmeister notifications@github.com wrote:

“Perhaps” here having the meaning of “I’ve been aware of this problem for a while, and didn’t want to care about it, but I’ve reached the point where I probably can’t ignore it any longer, and any “yes please” feedback will make me do this change.”

— Reply to this email directly or view it on GitHub.

lucaswerkmeister commented 9 years ago

Fine ;)

On 31.10.2014 00:23, Gavin King wrote:

Do it :)

Sent from my iPhone

On 30 Oct 2014, at 9:49 pm, Lucas Werkmeister notifications@github.com wrote:

“Perhaps” here having the meaning of “I’ve been aware of this problem for a while, and didn’t want to care about it, but I’ve reached the point where I probably can’t ignore it any longer, and any “yes please” feedback will make me do this change.”

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/ceylon/ceylon.formatter/issues/99#issuecomment-61187520.

lucaswerkmeister commented 9 years ago

Hm, should this also apply to parentheses? I’m a bit uncertain about

(1..j).fold(1, (Integer a, Integer b) => a*b)+1

where perhaps

(1..j).fold(1, (Integer a, Integer b) => a*b) + 1

would be better?

lucaswerkmeister commented 9 years ago

Oh… and this is also not really pretty:

1+2 + 3
lucaswerkmeister commented 9 years ago

Another case: I don’t like the look of e.key==e.item.

On the other hand, I could totally see a==b && x==y.

So what’s the rule here? Only omit the spaces within a larger expression?

lucaswerkmeister commented 9 years ago

How about this?

Omit spaces if

resulting in

1 + 2 + 3
x*y*z - a*b*c
a==b && c==d
gavinking commented 9 years ago

Well, that maybe makes a lot of sense.

lucaswerkmeister commented 9 years ago

Okay, so with a few tweaks, the worst remaining wart is:

-        value diff = token.stopIndex - token.startIndex - token.text.size + 1;
+        value diff = token.stopIndex-token.startIndex - token.text.size + 1;

So “the same kind of BinaryOperatorExpression” needs to mean “the same precedence”, not “the same type” (type(x) == type(y)).

lucaswerkmeister commented 9 years ago

Okay, done in the 99 branch. It would be great if someone else could go over a47093c4ad42e4580448b5f5acaa7da389e65e01 and 5e66b5cd20306d4a4df447234f9d045b93139de7 and tell me if the changes look acceptable.