ceylon / ceylon-spec

DEPRECATED
Apache License 2.0
108 stars 34 forks source link

Column of closing " of a multi-line string literal isn’t checked #999

Open lucaswerkmeister opened 10 years ago

lucaswerkmeister commented 10 years ago

The following code is accepted:

void run() {
    print(
        "foo
         bar
         baz
"
    );
}

Relevant part of the spec:

The column in which the first character of a string literal occurs, excluding the opening quote characters, is called the initial column of the string literal. Every following line of a multiline string literal must contain whitespace up to the initial column. That is, if the string contents begin at the nth character in a line of text, the following lines must start with n whitespace characters. This required whitespace is removed from the string literal during lexical analysis.

I think that means that the closing double quotes should have to be aligned as well.

lucaswerkmeister commented 10 years ago

LiteralVisitor.stripIndent only gets the text of the string literal, but it could still check that the WS of the last line has the right length.

I’ll try fixing this.

lucaswerkmeister commented 10 years ago

Ah, it’s not just the last line. The current stripIndent also allows blank lines to have any WS.

lucaswerkmeister commented 10 years ago

Whoa, lots of errors in ceylon.language with the fix…

lucaswerkmeister commented 10 years ago

Lots of documentation with wrong WS in ceylon.language. Most of it seems to be verbatim strings where a few blank lines have still only one space instead of three – they probably used to be regular strings, and the conversion didn’t catch the blank lines.

lucaswerkmeister commented 10 years ago

Oh, there’s also this:

"""Doc
   doc
   more doc
"""

Do we want to allow that?

gavinking commented 10 years ago

Well I think that's desirable. Some tools strip of trailing white space. We would not want that to break the code.

lucaswerkmeister commented 10 years ago

Hm, good point. Does the spec need updating then?

(Also, I’m still going to fix the doc whitespace in ceylon.language. You can then decide if you want to merge it or not.)

lucaswerkmeister commented 10 years ago

I’ve pushed my changes to my branches ceylon-spec:fix_999 (lucaswerkmeister@cac76ec32cb8ceaffa01b277ba6dd270ac940ea8) and ceylon.language:ceylonSpec999 (lucaswerkmeister/ceylon.language@eb7de62f4495da34add6148f67d75edb51cfcf74).