Chromium Code Reviews| Index: runtime/vm/scanner.cc |
| =================================================================== |
| --- runtime/vm/scanner.cc (revision 27888) |
| +++ runtime/vm/scanner.cc (working copy) |
| @@ -422,19 +422,14 @@ |
| // Entering string scanning mode. |
| BeginStringLiteral(c0_); |
| - string_is_multiline_ = (LookaheadChar(1) == c0_) && |
| - (LookaheadChar(2) == c0_); |
| + ReadChar(); |
| - ReadChar(); // Skip opening delimiter. |
| - if (string_is_multiline_) { |
| + if ((c0_ == string_delimiter_) && (LookaheadChar(1) == string_delimiter_)) { |
| + string_is_multiline_ = true; |
| ReadChar(); // Skip two additional string delimiters. |
| ReadChar(); |
| - if (c0_ == '\n') { |
| - // Skip first character of multiline string if it is a newline. |
| - ReadChar(); |
| - } |
| } |
| - ScanLiteralStringChars(is_raw); |
| + ScanLiteralStringChars(is_raw, true); |
|
Ivan Posva
2013/09/25 16:31:50
Can't you pass string_is_multiline_ here? As this
hausner
2013/09/25 17:06:49
Simplified as you suggested.
|
| } |
| @@ -497,7 +492,7 @@ |
| } |
| -void Scanner::ScanLiteralStringChars(bool is_raw) { |
| +void Scanner::ScanLiteralStringChars(bool is_raw, bool is_first_line) { |
| GrowableArray<int32_t> string_chars(64); |
| ASSERT(IsScanningString()); |
| @@ -595,6 +590,27 @@ |
| } |
| string_chars.Add(ch1); |
| } |
| + // The first line of a multi-line string is discarded if it only |
| + // contains whitespace. |
| + if (string_is_multiline_ && |
| + is_first_line && |
| + (string_chars.Last() == '\n')) { |
| + bool whitespace_only = true; |
| + // Last character is the newline, don't inspect it. |
| + const intptr_t len = string_chars.length() - 1; |
| + for (int i = 0; i < len; i++) { |
| + int32_t ch = string_chars[i]; |
| + if ((ch != ' ') && (ch != '\t')) { |
|
Ivan Posva
2013/09/25 16:31:50
Please clarify the definition of white-space defin
hausner
2013/09/25 17:06:49
Will do. I used the WHITESPACE production in the s
|
| + // Non-whitespace character, keep the first line. |
| + whitespace_only = false; |
| + break; |
| + } |
| + } |
| + if (whitespace_only) { |
| + string_chars.Clear(); // Discard characters on first line. |
| + } |
| + is_first_line = false; |
| + } |
| ReadChar(); |
| } |
| } |
| @@ -627,7 +643,7 @@ |
| break; |
| } |
| } else { |
| - ScanLiteralStringChars(false); |
| + ScanLiteralStringChars(false, false); |
| } |
| break; |
| } |