Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is a line in Dart source? #14073

Closed
peter-ahe-google opened this issue Oct 14, 2013 · 6 comments
Closed

What is a line in Dart source? #14073

peter-ahe-google opened this issue Oct 14, 2013 · 6 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@peter-ahe-google
Copy link
Contributor

The specification says: "Multiline strings are delimited by either matching triples of single quotes or matching triples of double quotes. If the first line of a multiline string consists solely of whitespace characters then that line is ignored, including the new line at its end."

This brings up the question of what is a line, and the "new line at its end"?

The specification includes the following grammar productions:

NEWLINE: \n | \r ;

WHITESPACE: ('\t' | ' ' | NEWLINE)+;

I see at least two problems with this definition:

  1. On Windows, a line is terminated by CRLF, that is, the Dart string '\r\n'. However, the definition of NEWLINE implies that we should only strip the first '\r' leaving the '\n'. The fix would be to change the NEWLINE production to:

NEWLINE: '\n' | '\r\n' ;

  1. The production for WHITESPACE includes NEWLINE, this leads to confusion when interpreting the quote in the beginning of this bug report.
@gbracha
Copy link
Contributor

gbracha commented Oct 14, 2013

(1) I am happy to adapt the specification to deal with WIndows.
(2) I see no confusion either way.


Added Accepted label.

@iposva-google
Copy link
Contributor

We should add the '\r\n' option, but leave the lone '\r' as well.

@peter-ahe-google
Copy link
Contributor Author

We don't need to support \r, if you're trying to build Dart on Mac OS 9, you have bigger problems than having to convert line endings.

@lrhn
Copy link
Member

lrhn commented Oct 15, 2013

If we start accepting non-ASCII line terminators, we should accept any single Unicode line terminator or line-terminating control character as well as the '\r\n' sequence. That would include a single '\r'.

Q.v. http://unicode.org/standard/reports/tr13/tr13-5.html

@peter-ahe-google
Copy link
Contributor Author

Upon further consideration, I agree with Ivan and Lasse: we should keep \r.

@peter-ahe-google peter-ahe-google added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Oct 15, 2013
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
lrhn added a commit that referenced this issue Jan 31, 2017
Now say that NEWLINE is one of CR, LF or CR+LF, and that all of these
contribute a single LF to the string value.

Fixes issue #14073
BUG= http://dartbug.com/14073
R=eernst@google.com, johnniwinther@google.com

Review-Url: https://codereview.chromium.org/2665613003 .
@lrhn
Copy link
Member

lrhn commented Feb 22, 2017

The spec has been updated to say that lines end in line-terminator sequences which are CR+LF, CR or LF, and that a line terminator only supplies one LF character to a multi-line string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants