| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of tree; | 5 part of tree; |
| 6 | 6 |
| 7 abstract class Visitor<R> { | 7 abstract class Visitor<R> { |
| 8 const Visitor(); | 8 const Visitor(); |
| 9 | 9 |
| 10 R visitNode(Node node); | 10 R visitNode(Node node); |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 if (identical(token.stringValue, 'false')) return false; | 819 if (identical(token.stringValue, 'false')) return false; |
| 820 (this.handler)(token, "not a bool ${token.value}"); | 820 (this.handler)(token, "not a bool ${token.value}"); |
| 821 throw false; | 821 throw false; |
| 822 } | 822 } |
| 823 | 823 |
| 824 accept(Visitor visitor) => visitor.visitLiteralBool(this); | 824 accept(Visitor visitor) => visitor.visitLiteralBool(this); |
| 825 } | 825 } |
| 826 | 826 |
| 827 | 827 |
| 828 class StringQuoting { | 828 class StringQuoting { |
| 829 static const StringQuoting SINGLELINE_DQ = | |
| 830 const StringQuoting($DQ, raw: false, leftQuoteLength: 1); | |
| 831 static const StringQuoting RAW_SINGLELINE_DQ = | |
| 832 const StringQuoting($DQ, raw: true, leftQuoteLength: 1); | |
| 833 static const StringQuoting MULTILINE_DQ = | |
| 834 const StringQuoting($DQ, raw: false, leftQuoteLength: 3); | |
| 835 static const StringQuoting RAW_MULTILINE_DQ = | |
| 836 const StringQuoting($DQ, raw: true, leftQuoteLength: 3); | |
| 837 static const StringQuoting MULTILINE_NL_DQ = | |
| 838 const StringQuoting($DQ, raw: false, leftQuoteLength: 4); | |
| 839 static const StringQuoting RAW_MULTILINE_NL_DQ = | |
| 840 const StringQuoting($DQ, raw: true, leftQuoteLength: 4); | |
| 841 static const StringQuoting MULTILINE_NL2_DQ = | |
| 842 const StringQuoting($DQ, raw: false, leftQuoteLength: 5); | |
| 843 static const StringQuoting RAW_MULTILINE_NL2_DQ = | |
| 844 const StringQuoting($DQ, raw: true, leftQuoteLength: 5); | |
| 845 static const StringQuoting SINGLELINE_SQ = | |
| 846 const StringQuoting($SQ, raw: false, leftQuoteLength: 1); | |
| 847 static const StringQuoting RAW_SINGLELINE_SQ = | |
| 848 const StringQuoting($SQ, raw: true, leftQuoteLength: 1); | |
| 849 static const StringQuoting MULTILINE_SQ = | |
| 850 const StringQuoting($SQ, raw: false, leftQuoteLength: 3); | |
| 851 static const StringQuoting RAW_MULTILINE_SQ = | |
| 852 const StringQuoting($SQ, raw: true, leftQuoteLength: 3); | |
| 853 static const StringQuoting MULTILINE_NL_SQ = | |
| 854 const StringQuoting($SQ, raw: false, leftQuoteLength: 4); | |
| 855 static const StringQuoting RAW_MULTILINE_NL_SQ = | |
| 856 const StringQuoting($SQ, raw: true, leftQuoteLength: 4); | |
| 857 static const StringQuoting MULTILINE_NL2_SQ = | |
| 858 const StringQuoting($SQ, raw: false, leftQuoteLength: 5); | |
| 859 static const StringQuoting RAW_MULTILINE_NL2_SQ = | |
| 860 const StringQuoting($SQ, raw: true, leftQuoteLength: 5); | |
| 861 | 829 |
| 830 /// Cache of common quotings. |
| 831 static const List<StringQuoting> _mapping = const <StringQuoting>[ |
| 832 const StringQuoting($SQ, raw: false, leftQuoteLength: 1), |
| 833 const StringQuoting($SQ, raw: true, leftQuoteLength: 1), |
| 834 const StringQuoting($DQ, raw: false, leftQuoteLength: 1), |
| 835 const StringQuoting($DQ, raw: true, leftQuoteLength: 1), |
| 836 // No string quotes with 2 characters. |
| 837 null, |
| 838 null, |
| 839 null, |
| 840 null, |
| 841 // Multiline quotings. |
| 842 const StringQuoting($SQ, raw: false, leftQuoteLength: 3), |
| 843 const StringQuoting($SQ, raw: true, leftQuoteLength: 3), |
| 844 const StringQuoting($DQ, raw: false, leftQuoteLength: 3), |
| 845 const StringQuoting($DQ, raw: true, leftQuoteLength: 3), |
| 846 // Leading single whitespace or espaped newline. |
| 847 const StringQuoting($SQ, raw: false, leftQuoteLength: 4), |
| 848 const StringQuoting($SQ, raw: true, leftQuoteLength: 4), |
| 849 const StringQuoting($DQ, raw: false, leftQuoteLength: 4), |
| 850 const StringQuoting($DQ, raw: true, leftQuoteLength: 4), |
| 851 // Other combinations of leading whitespace and/or escaped newline. |
| 852 const StringQuoting($SQ, raw: false, leftQuoteLength: 5), |
| 853 const StringQuoting($SQ, raw: true, leftQuoteLength: 5), |
| 854 const StringQuoting($DQ, raw: false, leftQuoteLength: 5), |
| 855 const StringQuoting($DQ, raw: true, leftQuoteLength: 5), |
| 856 const StringQuoting($SQ, raw: false, leftQuoteLength: 6), |
| 857 const StringQuoting($SQ, raw: true, leftQuoteLength: 6), |
| 858 const StringQuoting($DQ, raw: false, leftQuoteLength: 6), |
| 859 const StringQuoting($DQ, raw: true, leftQuoteLength: 6) |
| 860 ]; |
| 862 | 861 |
| 863 static const List<StringQuoting> mapping = const <StringQuoting>[ | |
| 864 SINGLELINE_DQ, | |
| 865 RAW_SINGLELINE_DQ, | |
| 866 MULTILINE_DQ, | |
| 867 RAW_MULTILINE_DQ, | |
| 868 MULTILINE_NL_DQ, | |
| 869 RAW_MULTILINE_NL_DQ, | |
| 870 MULTILINE_NL2_DQ, | |
| 871 RAW_MULTILINE_NL2_DQ, | |
| 872 SINGLELINE_SQ, | |
| 873 RAW_SINGLELINE_SQ, | |
| 874 MULTILINE_SQ, | |
| 875 RAW_MULTILINE_SQ, | |
| 876 MULTILINE_NL_SQ, | |
| 877 RAW_MULTILINE_NL_SQ, | |
| 878 MULTILINE_NL2_SQ, | |
| 879 RAW_MULTILINE_NL2_SQ | |
| 880 ]; | |
| 881 final bool raw; | 862 final bool raw; |
| 882 final int leftQuoteCharCount; | 863 final int leftQuoteCharCount; |
| 883 final int quote; | 864 final int quote; |
| 884 const StringQuoting(this.quote, {bool raw, int leftQuoteLength}) | 865 const StringQuoting(this.quote, { this.raw, int leftQuoteLength }) |
| 885 : this.raw = raw, this.leftQuoteCharCount = leftQuoteLength; | 866 : this.leftQuoteCharCount = leftQuoteLength; |
| 886 String get quoteChar => identical(quote, $DQ) ? '"' : "'"; | 867 String get quoteChar => identical(quote, $DQ) ? '"' : "'"; |
| 887 | 868 |
| 888 int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount; | 869 int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount; |
| 889 int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1; | 870 int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1; |
| 890 static StringQuoting getQuoting(int quote, bool raw, int quoteLength) { | 871 static StringQuoting getQuoting(int quote, bool raw, int leftQuoteLength) { |
| 891 int index = quoteLength - 1; | 872 int quoteKindOffset = (quote == $DQ) ? 2 : 0; |
| 892 if (quoteLength > 2) index -= 1; | 873 int rawOffset = raw ? 1 : 0; |
| 893 return mapping[(raw ? 1 : 0) + index * 2 + (identical(quote, $SQ) ? 8 : 0)]; | 874 int index = (leftQuoteLength - 1) * 4 + rawOffset + quoteKindOffset; |
| 875 if (index < _mapping.length) return _mapping[index]; |
| 876 return new StringQuoting(quote, raw: raw, leftQuoteLength: leftQuoteLength); |
| 894 } | 877 } |
| 895 } | 878 } |
| 896 | 879 |
| 897 /** | 880 /** |
| 898 * Superclass for classes representing string literals. | 881 * Superclass for classes representing string literals. |
| 899 */ | 882 */ |
| 900 abstract class StringNode extends Expression { | 883 abstract class StringNode extends Expression { |
| 901 DartString get dartString; | 884 DartString get dartString; |
| 902 bool get isInterpolation; | 885 bool get isInterpolation; |
| 903 | 886 |
| (...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 } | 2090 } |
| 2108 | 2091 |
| 2109 class IsInterpolationVisitor extends Visitor<bool> { | 2092 class IsInterpolationVisitor extends Visitor<bool> { |
| 2110 const IsInterpolationVisitor(); | 2093 const IsInterpolationVisitor(); |
| 2111 bool visitNode(Node node) => false; | 2094 bool visitNode(Node node) => false; |
| 2112 bool visitStringInterpolation(StringInterpolation node) => true; | 2095 bool visitStringInterpolation(StringInterpolation node) => true; |
| 2113 bool visitStringJuxtaposition(StringJuxtaposition node) | 2096 bool visitStringJuxtaposition(StringJuxtaposition node) |
| 2114 => node.isInterpolation; | 2097 => node.isInterpolation; |
| 2115 } | 2098 } |
| 2116 | 2099 |
| OLD | NEW |