eclipse-archived / ceylon.formatter

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

Wrong indentation for multi-line string templates #39

Closed lucaswerkmeister closed 10 years ago

lucaswerkmeister commented 10 years ago

Input:

void testIssue39() {
    print("Text `` "with template" ``
               that starts indented");
}

Output:

void testIssue39() {
    print("Text `` "with template" ``
                                   that starts indented");
}
lucaswerkmeister commented 10 years ago

The second line doesn’t even need to be indented. It’s just always aligned to the ``` of the string part it’s currently in, not the"` of the proper string start.

lucaswerkmeister commented 10 years ago

String templates can be nested, by the way:

void testIssue39() {
    print("This `` "
                    text `` "
                             has" ``" ``
           nested `` "
                      templates" ``");
    // but is printed without any indentation
}

Luckily, the grammar has different token types for string starts, mids, ends, and literals, so it should be possible to keep some stack of charPositionInLines.

lucaswerkmeister commented 10 years ago

Crud, even more problems. The (’s indentAfter can only start after the string is completely processed.

lucaswerkmeister commented 10 years ago

Oohh… I not only need to carry over the charPositionInLines for write’s sourceColumn, but also the targetColumn, which currently comes from the countingWriter.

lucaswerkmeister commented 10 years ago

YES! It works! Commit incoming, but YES!! Sorry, I’m excited, this bug had me really worried. Carry on.

lucaswerkmeister commented 10 years ago

Crud, even more problems. The (’s indentAfter can only start after the string is completely processed.

Somehow, this problem vanished, because I’m not dealing with it specifically… I’m okay with that :)