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

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

Issue 1042033002: Issue 23018. Fix for inlining multiline strings with leading whitespaces. (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
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.ast; 8 library engine.ast;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 10842 matching lines...) Expand 10 before | Expand all | Expand 10 after
10853 @override 10853 @override
10854 Token get beginToken => contents; 10854 Token get beginToken => contents;
10855 10855
10856 @override 10856 @override
10857 Iterable get childEntities => new ChildEntities()..add(contents); 10857 Iterable get childEntities => new ChildEntities()..add(contents);
10858 10858
10859 /** 10859 /**
10860 * Return the offset of the after-last contents character. 10860 * Return the offset of the after-last contents character.
10861 */ 10861 */
10862 int get contentsEnd { 10862 int get contentsEnd {
10863 int end = contents.end;
10864 String lexeme = contents.lexeme; 10863 String lexeme = contents.lexeme;
10865 if (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) || 10864 return offset + new StringLexemeHelper(lexeme, true, true).end;
10866 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27)) {
10867 end -= 3;
10868 } else {
10869 end -= 1;
10870 }
10871 return end;
10872 } 10865 }
10873 10866
10874 /** 10867 /**
10875 * Return the offset of the first contents character. 10868 * Return the offset of the first contents character.
10876 */ 10869 */
10877 int get contentsOffset { 10870 int get contentsOffset {
10878 int offset = contents.offset; 10871 int offset = contents.offset;
10879 String lexeme = contents.lexeme; 10872 String lexeme = contents.lexeme;
10880 if (lexeme.codeUnitAt(0) == 0x72) { 10873 return offset + new StringLexemeHelper(lexeme, true, true).start;
10881 offset += 1;
10882 }
10883 if (StringUtilities.startsWith3(lexeme, offset, 0x22, 0x22, 0x22) ||
10884 StringUtilities.startsWith3(lexeme, offset, 0x27, 0x27, 0x27)) {
10885 offset += 3;
10886 } else {
10887 offset += 1;
10888 }
10889 return offset;
10890 } 10874 }
10891 10875
10892 @override 10876 @override
10893 Token get endToken => contents; 10877 Token get endToken => contents;
10894 10878
10895 /** 10879 /**
10896 * Return the value of the literal. 10880 * Return the value of the literal.
10897 */ 10881 */
10898 String get value => _value; 10882 String get value => _value;
10899 10883
(...skipping 5586 matching lines...) Expand 10 before | Expand all | Expand 10 after
16486 _value = StringUtilities.intern(value); 16470 _value = StringUtilities.intern(value);
16487 } 16471 }
16488 16472
16489 @override 16473 @override
16490 Token get beginToken => literal; 16474 Token get beginToken => literal;
16491 16475
16492 @override 16476 @override
16493 Iterable get childEntities => new ChildEntities()..add(literal); 16477 Iterable get childEntities => new ChildEntities()..add(literal);
16494 16478
16495 @override 16479 @override
16496 int get contentsEnd { 16480 int get contentsEnd => offset + _helper.end;
16497 if (isMultiline) {
16498 return end - 3;
16499 }
16500 return end - 1;
16501 }
16502 16481
16503 @override 16482 @override
16504 int get contentsOffset { 16483 int get contentsOffset => offset + _helper.start;
16505 int contentsOffset = 0;
16506 if (isRaw) {
16507 contentsOffset += 1;
16508 }
16509 if (isMultiline) {
16510 contentsOffset += 3;
16511 } else {
16512 contentsOffset += 1;
16513 }
16514 return offset + contentsOffset;
16515 }
16516 16484
16517 @override 16485 @override
16518 Token get endToken => literal; 16486 Token get endToken => literal;
16519 16487
16520 @override 16488 @override
16521 bool get isMultiline { 16489 bool get isMultiline => _helper.isMultiline;
16522 String lexeme = literal.lexeme;
16523 if (lexeme.length < 3) {
16524 return false;
16525 }
16526 // skip 'r'
16527 int offset = 0;
16528 if (isRaw) {
16529 offset = 1;
16530 }
16531 // check prefix
16532 return StringUtilities.startsWith3(lexeme, offset, 0x22, 0x22, 0x22) ||
16533 StringUtilities.startsWith3(lexeme, offset, 0x27, 0x27, 0x27);
16534 }
16535 16490
16536 @override 16491 @override
16537 bool get isRaw => literal.lexeme.codeUnitAt(0) == 0x72; 16492 bool get isRaw => _helper.isRaw;
16538 16493
16539 @override 16494 @override
16540 bool get isSingleQuoted { 16495 bool get isSingleQuoted => _helper.isSingleQuoted;
16541 String lexeme = literal.lexeme;
16542 if (lexeme.isEmpty) {
16543 return false;
16544 }
16545 int codeZero = lexeme.codeUnitAt(0);
16546 if (codeZero == 0x72) {
16547 return lexeme.length > 1 && lexeme.codeUnitAt(1) == 0x27;
16548 }
16549 return codeZero == 0x27;
16550 }
16551 16496
16552 @override 16497 @override
16553 bool get isSynthetic => literal.isSynthetic; 16498 bool get isSynthetic => literal.isSynthetic;
16554 16499
16555 /** 16500 /**
16556 * Return the value of the literal. 16501 * Return the value of the literal.
16557 */ 16502 */
16558 String get value => _value; 16503 String get value => _value;
16559 16504
16560 /** 16505 /**
16561 * Set the value of the literal to the given [string]. 16506 * Set the value of the literal to the given [string].
16562 */ 16507 */
16563 void set value(String string) { 16508 void set value(String string) {
16564 _value = StringUtilities.intern(_value); 16509 _value = StringUtilities.intern(_value);
16565 } 16510 }
16566 16511
16512 StringLexemeHelper get _helper {
Brian Wilkerson 2015/03/28 00:38:20 Use '=>'?
16513 return new StringLexemeHelper(literal.lexeme, true, true);
16514 }
16515
16567 @override 16516 @override
16568 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this); 16517 accept(AstVisitor visitor) => visitor.visitSimpleStringLiteral(this);
16569 16518
16570 @override 16519 @override
16571 void visitChildren(AstVisitor visitor) { 16520 void visitChildren(AstVisitor visitor) {
16572 // There are no children to visit. 16521 // There are no children to visit.
16573 } 16522 }
16574 16523
16575 @override 16524 @override
16576 void _appendStringValue(StringBuffer buffer) { 16525 void _appendStringValue(StringBuffer buffer) {
16577 buffer.write(value); 16526 buffer.write(value);
16578 } 16527 }
16579 } 16528 }
16580 16529
16581 /** 16530 /**
16582 * A single string literal expression. 16531 * A single string literal expression.
16583 * 16532 *
16584 * > singleStringLiteral ::= 16533 * > singleStringLiteral ::=
16585 * > [SimpleStringLiteral] 16534 * > [SimpleStringLiteral]
16586 * > | [StringInterpolation] 16535 * > | [StringInterpolation]
16587 */ 16536 */
16588 abstract class SingleStringLiteral extends StringLiteral { 16537 abstract class SingleStringLiteral extends StringLiteral {
16589 /** 16538 /**
16590 * Return the offset of the after-last contents character. 16539 * Return the offset of the after-last contents character.
16591 */ 16540 */
16592 int get contentsEnd; 16541 int get contentsEnd;
16593 16542
16594 /** 16543 /**
16595 * Return the offset of the first contents character. 16544 * Return the offset of the first contents character.
16545 * If the string is multiline, then leading whitespaces are skipped.
16596 */ 16546 */
16597 int get contentsOffset; 16547 int get contentsOffset;
16598 16548
16599 /** 16549 /**
16600 * Return `true` if this string literal is a multi-line string. 16550 * Return `true` if this string literal is a multi-line string.
16601 */ 16551 */
16602 bool get isMultiline; 16552 bool get isMultiline;
16603 16553
16604 /** 16554 /**
16605 * Return `true` if this string literal is a raw string. 16555 * Return `true` if this string literal is a raw string.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
16680 16630
16681 /** 16631 /**
16682 * Return the elements that will be composed to produce the resulting string. 16632 * Return the elements that will be composed to produce the resulting string.
16683 */ 16633 */
16684 NodeList<InterpolationElement> get elements => _elements; 16634 NodeList<InterpolationElement> get elements => _elements;
16685 16635
16686 @override 16636 @override
16687 Token get endToken => _elements.endToken; 16637 Token get endToken => _elements.endToken;
16688 16638
16689 @override 16639 @override
16690 bool get isMultiline { 16640 bool get isMultiline => _firstHelper.isMultiline;
16691 InterpolationString element = _elements.first;
16692 String lexeme = element.contents.lexeme;
16693 if (lexeme.length < 3) {
16694 return false;
16695 }
16696 return StringUtilities.startsWith3(lexeme, 0, 0x22, 0x22, 0x22) ||
16697 StringUtilities.startsWith3(lexeme, 0, 0x27, 0x27, 0x27);
16698 }
16699 16641
16700 @override 16642 @override
16701 bool get isRaw => false; 16643 bool get isRaw => false;
16702 16644
16703 @override 16645 @override
16704 bool get isSingleQuoted { 16646 bool get isSingleQuoted => _firstHelper.isSingleQuoted;
16647
16648 StringLexemeHelper get _firstHelper {
16705 InterpolationString lastString = _elements.first; 16649 InterpolationString lastString = _elements.first;
16706 String lexeme = lastString.contents.lexeme; 16650 String lexeme = lastString.contents.lexeme;
16707 return StringUtilities.startsWithChar(lexeme, 0x27); 16651 return new StringLexemeHelper(lexeme, true, false);
16708 } 16652 }
16709 16653
16710 @override 16654 @override
16711 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this); 16655 accept(AstVisitor visitor) => visitor.visitStringInterpolation(this);
16712 16656
16713 @override 16657 @override
16714 void visitChildren(AstVisitor visitor) { 16658 void visitChildren(AstVisitor visitor) {
16715 _elements.accept(visitor); 16659 _elements.accept(visitor);
16716 } 16660 }
16717 16661
16718 @override 16662 @override
16719 void _appendStringValue(StringBuffer buffer) { 16663 void _appendStringValue(StringBuffer buffer) {
16720 throw new IllegalArgumentException(); 16664 throw new IllegalArgumentException();
16721 } 16665 }
16722 } 16666 }
16723 16667
16724 /** 16668 /**
16669 * A helper for analyzing string lexemes.
16670 */
16671 class StringLexemeHelper {
16672 final String lexeme;
16673 final bool isFirst;
16674 final bool isLast;
16675
16676 bool isRaw = false;
16677 bool isSingleQuoted = false;
16678 bool isMultiline = false;
16679 int start = 0;
16680 int end;
16681
16682 StringLexemeHelper(this.lexeme, this.isFirst, this.isLast) {
16683 isRaw = StringUtilities.startsWithChar(lexeme, 0x72);
16684 if (isRaw) {
16685 start++;
16686 }
16687 if (StringUtilities.startsWith3(lexeme, start, 0x27, 0x27, 0x27)) {
16688 isSingleQuoted = true;
16689 isMultiline = true;
16690 start += 3;
16691 start = _trimInitialWhitespace(start);
16692 } else if (StringUtilities.startsWith3(lexeme, start, 0x22, 0x22, 0x22)) {
16693 isSingleQuoted = false;
16694 isMultiline = true;
16695 start += 3;
16696 start = _trimInitialWhitespace(start);
16697 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x27) {
16698 isSingleQuoted = true;
16699 isMultiline = false;
16700 start++;
16701 } else if (start < lexeme.length && lexeme.codeUnitAt(start) == 0x22) {
16702 isSingleQuoted = false;
16703 isMultiline = false;
16704 start++;
16705 }
16706 end = lexeme.length;
16707 if (isLast) {
16708 if (StringUtilities.endsWith3(lexeme, 0x22, 0x22, 0x22) ||
16709 StringUtilities.endsWith3(lexeme, 0x27, 0x27, 0x27)) {
16710 end -= 3;
16711 } else if (StringUtilities.endsWithChar(lexeme, 0x22) ||
16712 StringUtilities.endsWithChar(lexeme, 0x27)) {
16713 end -= 1;
16714 }
16715 }
16716 }
16717
16718 /**
16719 * Given the [lexeme] for a multi-line string whose content begins at the
16720 * given [start] index, return the index of the first character that is
16721 * included in the value of the string. According to the specification:
16722 *
16723 * If the first line of a multiline string consists solely of the whitespace
16724 * characters defined by the production WHITESPACE 20.1), possibly prefixed
16725 * by \, then that line is ignored, including the new line at its end.
16726 */
16727 int _trimInitialWhitespace(int start) {
16728 int length = lexeme.length;
16729 int index = start;
16730 while (index < length) {
16731 int currentChar = lexeme.codeUnitAt(index);
16732 if (currentChar == 0x0D) {
16733 if (index + 1 < length && lexeme.codeUnitAt(index + 1) == 0x0A) {
16734 return index + 2;
16735 }
16736 return index + 1;
16737 } else if (currentChar == 0x0A) {
16738 return index + 1;
16739 } else if (currentChar == 0x5C) {
16740 if (index + 1 >= length) {
16741 return start;
16742 }
16743 currentChar = lexeme.codeUnitAt(index + 1);
16744 if (currentChar != 0x0D &&
16745 currentChar != 0x0A &&
16746 currentChar != 0x09 &&
16747 currentChar != 0x20) {
16748 return start;
16749 }
16750 } else if (currentChar != 0x09 && currentChar != 0x20) {
16751 return start;
16752 }
16753 index++;
16754 }
16755 return start;
16756 }
16757 }
16758
16759 /**
16725 * A string literal expression. 16760 * A string literal expression.
16726 * 16761 *
16727 * > stringLiteral ::= 16762 * > stringLiteral ::=
16728 * > [SimpleStringLiteral] 16763 * > [SimpleStringLiteral]
16729 * > | [AdjacentStrings] 16764 * > | [AdjacentStrings]
16730 * > | [StringInterpolation] 16765 * > | [StringInterpolation]
16731 */ 16766 */
16732 abstract class StringLiteral extends Literal { 16767 abstract class StringLiteral extends Literal {
16733 /** 16768 /**
16734 * Return the value of the string literal, or `null` if the string is not a 16769 * Return the value of the string literal, or `null` if the string is not a
(...skipping 3352 matching lines...) Expand 10 before | Expand all | Expand 10 after
20087 } 20122 }
20088 20123
20089 @override 20124 @override
20090 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); 20125 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
20091 20126
20092 @override 20127 @override
20093 void visitChildren(AstVisitor visitor) { 20128 void visitChildren(AstVisitor visitor) {
20094 _safelyVisitChild(_expression, visitor); 20129 _safelyVisitChild(_expression, visitor);
20095 } 20130 }
20096 } 20131 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/services/refactoring/inline_local_test.dart ('k') | pkg/analyzer/lib/src/generated/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698