Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(897)

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 1038353002: Revert "Fix value computation for multi-line strings (issue 22993)" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser; 8 library engine.parser;
9 9
10 import "dart:math" as math; 10 import "dart:math" as math;
(...skipping 3412 matching lines...) Expand 10 before | Expand all | Expand 10 after
3423 } 3423 }
3424 if (scalarValue < Character.MAX_VALUE) { 3424 if (scalarValue < Character.MAX_VALUE) {
3425 buffer.writeCharCode(scalarValue); 3425 buffer.writeCharCode(scalarValue);
3426 } else { 3426 } else {
3427 buffer.write(Character.toChars(scalarValue)); 3427 buffer.write(Character.toChars(scalarValue));
3428 } 3428 }
3429 } 3429 }
3430 3430
3431 /** 3431 /**
3432 * Return the content of a string with the given literal representation. The 3432 * Return the content of a string with the given literal representation. The
3433 * [lexeme] is the literal representation of the string. The flag [isFirst] is 3433 * [lexeme] is the literal representation of the string. The flag [first] is
3434 * `true` if this is the first token in a string literal. The flag [isLast] is 3434 * `true` if this is the first token in a string literal. The flag [last] is
3435 * `true` if this is the last token in a string literal. 3435 * `true` if this is the last token in a string literal.
3436 */ 3436 */
3437 String _computeStringValue(String lexeme, bool isFirst, bool isLast) { 3437 String _computeStringValue(String lexeme, bool first, bool last) {
3438 bool isRaw = false; 3438 bool isRaw = false;
3439 int start = 0; 3439 int start = 0;
3440 if (isFirst) { 3440 if (first) {
3441 if (StringUtilities.startsWith4(lexeme, 0, 0x72, 0x22, 0x22, 0x22) || 3441 if (StringUtilities.startsWith4(lexeme, 0, 0x72, 0x22, 0x22, 0x22) ||
3442 StringUtilities.startsWith4(lexeme, 0, 0x72, 0x27, 0x27, 0x27)) { 3442 StringUtilities.startsWith4(lexeme, 0, 0x72, 0x27, 0x27, 0x27)) {
3443 isRaw = true; 3443 isRaw = true;
3444 start += 4; 3444 start += 4;
3445 if (isFirst) {
3446 start = _trimInitialWhitespace(lexeme, start);
3447 }
3448 } else if (StringUtilities.startsWith2(lexeme, 0, 0x72, 0x22) || 3445 } else if (StringUtilities.startsWith2(lexeme, 0, 0x72, 0x22) ||
3449 StringUtilities.startsWith2(lexeme, 0, 0x72, 0x27)) { 3446 StringUtilities.startsWith2(lexeme, 0, 0x72, 0x27)) {
3450 isRaw = true; 3447 isRaw = true;
3451 start += 2; 3448 start += 2;
3452 } else if (StringUtilities.startsWith3(lexeme, 0, 0x22, 0x22, 0x22) || 3449 } else if (StringUtilities.startsWith3(lexeme, 0, 0x22, 0x22, 0x22) ||
3453 StringUtilities.startsWith3(lexeme, 0, 0x27, 0x27, 0x27)) { 3450 StringUtilities.startsWith3(lexeme, 0, 0x27, 0x27, 0x27)) {
3454 start += 3; 3451 start += 3;
3455 if (isFirst) {
3456 start = _trimInitialWhitespace(lexeme, start);
3457 }
3458 } else if (StringUtilities.startsWithChar(lexeme, 0x22) || 3452 } else if (StringUtilities.startsWithChar(lexeme, 0x22) ||
3459 StringUtilities.startsWithChar(lexeme, 0x27)) { 3453 StringUtilities.startsWithChar(lexeme, 0x27)) {
3460 start += 1; 3454 start += 1;
3461 } 3455 }
3462 } 3456 }
3463 int end = lexeme.length; 3457 int end = lexeme.length;
3464 if (isLast) { 3458 if (last) {
3465 if (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) || 3459 if (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) ||
3466 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27)) { 3460 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27)) {
3467 end -= 3; 3461 end -= 3;
3468 } else if (StringUtilities.endsWithChar(lexeme, 0x22) || 3462 } else if (StringUtilities.endsWithChar(lexeme, 0x22) ||
3469 StringUtilities.endsWithChar(lexeme, 0x27)) { 3463 StringUtilities.endsWithChar(lexeme, 0x27)) {
3470 end -= 1; 3464 end -= 1;
3471 } 3465 }
3472 } 3466 }
3473 if (end - start + 1 < 0) { 3467 if (end - start + 1 < 0) {
3474 AnalysisEngine.instance.logger.logError( 3468 AnalysisEngine.instance.logger.logError(
3475 "Internal error: computeStringValue($lexeme, $isFirst, $isLast)"); 3469 "Internal error: computeStringValue($lexeme, $first, $last)");
3476 return ""; 3470 return "";
3477 } 3471 }
3478 if (isRaw) { 3472 if (isRaw) {
3479 return lexeme.substring(start, end); 3473 return lexeme.substring(start, end);
3480 } 3474 }
3481 StringBuffer buffer = new StringBuffer(); 3475 StringBuffer buffer = new StringBuffer();
3482 int index = start; 3476 int index = start;
3483 while (index < end) { 3477 while (index < end) {
3484 index = _translateCharacter(buffer, lexeme, index); 3478 index = _translateCharacter(buffer, lexeme, index);
3485 } 3479 }
(...skipping 4763 matching lines...) Expand 10 before | Expand all | Expand 10 after
8249 } 8243 }
8250 return currentIndex + 4; 8244 return currentIndex + 4;
8251 } 8245 }
8252 } else { 8246 } else {
8253 buffer.writeCharCode(currentChar); 8247 buffer.writeCharCode(currentChar);
8254 } 8248 }
8255 return currentIndex + 1; 8249 return currentIndex + 1;
8256 } 8250 }
8257 8251
8258 /** 8252 /**
8259 * Given the [lexeme] for a multi-line string whose content begins at the
8260 * given [start] index, return the index of the first character that is
8261 * included in the value of the string. According to the specification:
8262 *
8263 * If the first line of a multiline string consists solely of the whitespace
8264 * characters defined by the production WHITESPACE 20.1), possibly prefixed
8265 * by \, then that line is ignored, including the new line at its end.
8266 */
8267 int _trimInitialWhitespace(String lexeme, int start) {
8268 int length = lexeme.length;
8269 int index = start;
8270 while (index < length) {
8271 int currentChar = lexeme.codeUnitAt(index);
8272 if (currentChar == 0x0D) {
8273 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) {
8274 return index + 2;
8275 }
8276 return index + 1;
8277 } else if (currentChar == 0x0A) {
8278 return index + 1;
8279 } else if (currentChar == 0x5C) {
8280 if (index + 1 >= length) {
8281 return start;
8282 }
8283 currentChar = lexeme.codeUnitAt(index + 1);
8284 if (currentChar != 0x0D &&
8285 currentChar != 0x0A &&
8286 currentChar != 0x09 &&
8287 currentChar != 0x20) {
8288 return start;
8289 }
8290 } else if (currentChar != 0x09 && currentChar != 0x20) {
8291 return start;
8292 }
8293 index++;
8294 }
8295 return start;
8296 }
8297
8298 /**
8299 * Decrements the error reporting lock level. If level is more than `0`, then 8253 * Decrements the error reporting lock level. If level is more than `0`, then
8300 * [reportError] wont report any error. 8254 * [reportError] wont report any error.
8301 */ 8255 */
8302 void _unlockErrorListener() { 8256 void _unlockErrorListener() {
8303 if (_errorListenerLock == 0) { 8257 if (_errorListenerLock == 0) {
8304 throw new IllegalStateException( 8258 throw new IllegalStateException(
8305 "Attempt to unlock not locked error listener."); 8259 "Attempt to unlock not locked error listener.");
8306 } 8260 }
8307 _errorListenerLock--; 8261 _errorListenerLock--;
8308 } 8262 }
(...skipping 2274 matching lines...) Expand 10 before | Expand all | Expand 10 after
10583 } 10537 }
10584 10538
10585 /** 10539 /**
10586 * Copy resolution data from the [fromNode] to the [toNode]. 10540 * Copy resolution data from the [fromNode] to the [toNode].
10587 */ 10541 */
10588 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 10542 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
10589 ResolutionCopier copier = new ResolutionCopier(); 10543 ResolutionCopier copier = new ResolutionCopier();
10590 copier._isEqualNodes(fromNode, toNode); 10544 copier._isEqualNodes(fromNode, toNode);
10591 } 10545 }
10592 } 10546 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698