| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface Visitor<R> { | 5 interface Visitor<R> { |
| 6 R visitBlock(Block node); | 6 R visitBlock(Block node); |
| 7 R visitBreakStatement(BreakStatement node); | 7 R visitBreakStatement(BreakStatement node); |
| 8 R visitCatchBlock(CatchBlock node); | 8 R visitCatchBlock(CatchBlock node); |
| 9 R visitClassNode(ClassNode node); | 9 R visitClassNode(ClassNode node); |
| 10 R visitConditional(Conditional node); | 10 R visitConditional(Conditional node); |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 case Keyword.TRUE: return true; | 605 case Keyword.TRUE: return true; |
| 606 case Keyword.FALSE: return false; | 606 case Keyword.FALSE: return false; |
| 607 default: | 607 default: |
| 608 (this.handler)(token, "not a bool ${token.value}"); | 608 (this.handler)(token, "not a bool ${token.value}"); |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 | 611 |
| 612 accept(Visitor visitor) => visitor.visitLiteralBool(this); | 612 accept(Visitor visitor) => visitor.visitLiteralBool(this); |
| 613 } | 613 } |
| 614 | 614 |
| 615 |
| 616 class StringQuoting { |
| 617 static final StringQuoting SINGLELINE_DQ = |
| 618 const StringQuoting($DQ, raw: false, multiline: false); |
| 619 static final StringQuoting RAW_SINGLELINE_DQ = |
| 620 const StringQuoting($DQ, raw: true, multiline: false); |
| 621 static final StringQuoting MULTILINE_DQ = |
| 622 const StringQuoting($DQ, raw: false, multiline: true); |
| 623 static final StringQuoting RAW_MULTILINE_DQ = |
| 624 const StringQuoting($DQ, raw: true, multiline: true); |
| 625 static final StringQuoting SINGLELINE_SQ = |
| 626 const StringQuoting($SQ, raw: false, multiline: false); |
| 627 static final StringQuoting RAW_SINGLELINE_SQ = |
| 628 const StringQuoting($SQ, raw: true, multiline: false); |
| 629 static final StringQuoting MULTILINE_SQ = |
| 630 const StringQuoting($SQ, raw: false, multiline: true); |
| 631 static final StringQuoting RAW_MULTILINE_SQ = |
| 632 const StringQuoting($SQ, raw: true, multiline: true); |
| 633 static final List<StringQuoting> mapping = const <StringQuoting>[ |
| 634 SINGLELINE_DQ, |
| 635 RAW_SINGLELINE_DQ, |
| 636 MULTILINE_DQ, |
| 637 RAW_MULTILINE_DQ, |
| 638 SINGLELINE_SQ, |
| 639 RAW_SINGLELINE_SQ, |
| 640 MULTILINE_DQ, |
| 641 RAW_MULTILINE_SQ |
| 642 ]; |
| 643 final bool raw; |
| 644 final bool multiline; |
| 645 final int quote; |
| 646 const StringQuoting(this.quote, [bool raw, bool multiline]) |
| 647 : this.raw = raw, this.multiline = multiline; |
| 648 String get quoteChar() => quote === $DQ ? '"' : "'"; |
| 649 |
| 650 int get leftQuoteLength() => (raw ? 1 : 0) + (multiline ? 3 : 1); |
| 651 int get rightQuoteLength() => multiline ? 3 : 1; |
| 652 static StringQuoting get(int quote, bool raw, bool multiline) => |
| 653 mapping[(raw ? 1 : 0) + (multiline ? 2 : 0) + (quote === $SQ ? 4 : 0)]; |
| 654 } |
| 655 |
| 656 /** |
| 657 * A wrapper around a SourceString that stores extra information about |
| 658 * the (potentially implicit) quoting style of the original string. |
| 659 * For most strings, the quotes are included in the [source], but |
| 660 * parts of strings from a string interpolation might be missing one or |
| 661 * both quotes. |
| 662 */ |
| 663 class QuotedString { |
| 664 // A source-backed string literal without the quotes. |
| 665 final SourceString source; |
| 666 // The quoting style of the original string literal. |
| 667 // Whether it's raw or multi-line impacts the interpretation of |
| 668 // the string literal content. Whether it's single- or double-quoted |
| 669 // is only used as a hint later. |
| 670 final StringQuoting quoting; |
| 671 /** Actual length of the corresponding, parsed, Dart string */ |
| 672 final int length; |
| 673 |
| 674 const QuotedString(this.source, this.quoting, this.length); |
| 675 /** |
| 676 * Construct a [QuotedString] containing exactly the given string. |
| 677 * The choice of quoting ensures that all characters of the original |
| 678 * string are valid and has their exact meaning. |
| 679 */ |
| 680 QuotedString.literal(String string) |
| 681 : source = new SourceString(string), |
| 682 quoting = StringQuoting.RAW_MULTILINE_DQ, |
| 683 length = string.length; |
| 684 |
| 685 bool isEmpty() => source.isEmpty(); |
| 686 Iterator<int> iterator() => source.iterator(); |
| 687 |
| 688 bool definitlyEquals(QuotedString other) { |
| 689 return source === other.source && quoting === other.quoting; |
| 690 } |
| 691 } |
| 692 |
| 693 |
| 615 class LiteralString extends Literal<SourceString> { | 694 class LiteralString extends Literal<SourceString> { |
| 616 LiteralString(Token token) : super(token, null); | 695 /** Set on validated string literals. */ |
| 696 final QuotedString quotedString = null; |
| 697 |
| 698 LiteralString(Token token, this.quotedString) : super(token, null); |
| 617 | 699 |
| 618 LiteralString asLiteralString() => this; | 700 LiteralString asLiteralString() => this; |
| 619 | 701 |
| 702 bool isValidated() => quotedString !== null; |
| 703 |
| 620 SourceString get value() => token.value; | 704 SourceString get value() => token.value; |
| 621 | 705 |
| 622 accept(Visitor visitor) => visitor.visitLiteralString(this); | 706 accept(Visitor visitor) => visitor.visitLiteralString(this); |
| 623 } | 707 } |
| 624 | 708 |
| 625 class LiteralNull extends Literal<SourceString> { | 709 class LiteralNull extends Literal<SourceString> { |
| 626 LiteralNull(Token token) : super(token, null); | 710 LiteralNull(Token token) : super(token, null); |
| 627 | 711 |
| 628 LiteralNull asLiteralNull() => this; | 712 LiteralNull asLiteralNull() => this; |
| 629 | 713 |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 | 1339 |
| 1256 visitChildren(Visitor visitor) { | 1340 visitChildren(Visitor visitor) { |
| 1257 formals.accept(visitor); | 1341 formals.accept(visitor); |
| 1258 block.accept(visitor); | 1342 block.accept(visitor); |
| 1259 } | 1343 } |
| 1260 | 1344 |
| 1261 Token getBeginToken() => catchKeyword; | 1345 Token getBeginToken() => catchKeyword; |
| 1262 | 1346 |
| 1263 Token getEndToken() => block.getEndToken(); | 1347 Token getEndToken() => block.getEndToken(); |
| 1264 } | 1348 } |
| OLD | NEW |