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 on operator collision #83

Closed lucaswerkmeister closed 9 years ago

lucaswerkmeister commented 9 years ago

At the moment, - --i is formatted as ---i, which the compiler lexes as -- -i instead. We should put a space in there.

In fact, even when the syntax works out, we should add a space to avoid confusion:

void run() {
    variable Integer i = 0;
    print(i---i);
    print(i- --i);
    print(i-- -i);
    print(i- - -i);
}

All four printed expressions are valid, and I have no idea as which of the latter three the first one is parsed.

lucaswerkmeister commented 9 years ago

And for symmetry, let’s even add a space in the slightly less ambiguous case of i++-i.

lucaswerkmeister commented 9 years ago

In fact, let’s not even care about pre- or postfix, ‘cause I think -i-- is still problematic.

lucaswerkmeister commented 9 years ago

Not enough, because the ^ operator has precedence between prefix - and --, i. e. - --i ^ j.

lucaswerkmeister commented 9 years ago

OTOH, -i ^ j (as we output now) is also really confusing, so let’s just add a space any time the term isn’t a Primary.