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

Unified Diff: sdk/lib/_internal/compiler/implementation/tree/nodes.dart

Issue 336413002: Allow whitespace and \ before the first newline of multiline string. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgot to save. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/string_validator.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/tree/nodes.dart
diff --git a/sdk/lib/_internal/compiler/implementation/tree/nodes.dart b/sdk/lib/_internal/compiler/implementation/tree/nodes.dart
index bd96b3c213f3c1645620a7fd7953ddbff3774b02..0e0305c2ff8ce79c4020d1f9aaefcc495ef0a534 100644
--- a/sdk/lib/_internal/compiler/implementation/tree/nodes.dart
+++ b/sdk/lib/_internal/compiler/implementation/tree/nodes.dart
@@ -826,71 +826,54 @@ class LiteralBool extends Literal<bool> {
class StringQuoting {
- static const StringQuoting SINGLELINE_DQ =
- const StringQuoting($DQ, raw: false, leftQuoteLength: 1);
- static const StringQuoting RAW_SINGLELINE_DQ =
- const StringQuoting($DQ, raw: true, leftQuoteLength: 1);
- static const StringQuoting MULTILINE_DQ =
- const StringQuoting($DQ, raw: false, leftQuoteLength: 3);
- static const StringQuoting RAW_MULTILINE_DQ =
- const StringQuoting($DQ, raw: true, leftQuoteLength: 3);
- static const StringQuoting MULTILINE_NL_DQ =
- const StringQuoting($DQ, raw: false, leftQuoteLength: 4);
- static const StringQuoting RAW_MULTILINE_NL_DQ =
- const StringQuoting($DQ, raw: true, leftQuoteLength: 4);
- static const StringQuoting MULTILINE_NL2_DQ =
- const StringQuoting($DQ, raw: false, leftQuoteLength: 5);
- static const StringQuoting RAW_MULTILINE_NL2_DQ =
- const StringQuoting($DQ, raw: true, leftQuoteLength: 5);
- static const StringQuoting SINGLELINE_SQ =
- const StringQuoting($SQ, raw: false, leftQuoteLength: 1);
- static const StringQuoting RAW_SINGLELINE_SQ =
- const StringQuoting($SQ, raw: true, leftQuoteLength: 1);
- static const StringQuoting MULTILINE_SQ =
- const StringQuoting($SQ, raw: false, leftQuoteLength: 3);
- static const StringQuoting RAW_MULTILINE_SQ =
- const StringQuoting($SQ, raw: true, leftQuoteLength: 3);
- static const StringQuoting MULTILINE_NL_SQ =
- const StringQuoting($SQ, raw: false, leftQuoteLength: 4);
- static const StringQuoting RAW_MULTILINE_NL_SQ =
- const StringQuoting($SQ, raw: true, leftQuoteLength: 4);
- static const StringQuoting MULTILINE_NL2_SQ =
- const StringQuoting($SQ, raw: false, leftQuoteLength: 5);
- static const StringQuoting RAW_MULTILINE_NL2_SQ =
- const StringQuoting($SQ, raw: true, leftQuoteLength: 5);
-
-
- static const List<StringQuoting> mapping = const <StringQuoting>[
- SINGLELINE_DQ,
- RAW_SINGLELINE_DQ,
- MULTILINE_DQ,
- RAW_MULTILINE_DQ,
- MULTILINE_NL_DQ,
- RAW_MULTILINE_NL_DQ,
- MULTILINE_NL2_DQ,
- RAW_MULTILINE_NL2_DQ,
- SINGLELINE_SQ,
- RAW_SINGLELINE_SQ,
- MULTILINE_SQ,
- RAW_MULTILINE_SQ,
- MULTILINE_NL_SQ,
- RAW_MULTILINE_NL_SQ,
- MULTILINE_NL2_SQ,
- RAW_MULTILINE_NL2_SQ
+
+ /// Cache of common quotings.
+ static const List<StringQuoting> _mapping = const <StringQuoting>[
+ const StringQuoting($SQ, raw: false, leftQuoteLength: 1),
+ const StringQuoting($SQ, raw: true, leftQuoteLength: 1),
+ const StringQuoting($DQ, raw: false, leftQuoteLength: 1),
+ const StringQuoting($DQ, raw: true, leftQuoteLength: 1),
+ // No string quotes with 2 characters.
+ null,
+ null,
+ null,
+ null,
+ // Multiline quotings.
+ const StringQuoting($SQ, raw: false, leftQuoteLength: 3),
+ const StringQuoting($SQ, raw: true, leftQuoteLength: 3),
+ const StringQuoting($DQ, raw: false, leftQuoteLength: 3),
+ const StringQuoting($DQ, raw: true, leftQuoteLength: 3),
+ // Leading single whitespace or espaped newline.
+ const StringQuoting($SQ, raw: false, leftQuoteLength: 4),
+ const StringQuoting($SQ, raw: true, leftQuoteLength: 4),
+ const StringQuoting($DQ, raw: false, leftQuoteLength: 4),
+ const StringQuoting($DQ, raw: true, leftQuoteLength: 4),
+ // Other combinations of leading whitespace and/or escaped newline.
+ const StringQuoting($SQ, raw: false, leftQuoteLength: 5),
+ const StringQuoting($SQ, raw: true, leftQuoteLength: 5),
+ const StringQuoting($DQ, raw: false, leftQuoteLength: 5),
+ const StringQuoting($DQ, raw: true, leftQuoteLength: 5),
+ const StringQuoting($SQ, raw: false, leftQuoteLength: 6),
+ const StringQuoting($SQ, raw: true, leftQuoteLength: 6),
+ const StringQuoting($DQ, raw: false, leftQuoteLength: 6),
+ const StringQuoting($DQ, raw: true, leftQuoteLength: 6)
];
+
final bool raw;
final int leftQuoteCharCount;
final int quote;
- const StringQuoting(this.quote, {bool raw, int leftQuoteLength})
- : this.raw = raw, this.leftQuoteCharCount = leftQuoteLength;
+ const StringQuoting(this.quote, { this.raw, int leftQuoteLength })
+ : this.leftQuoteCharCount = leftQuoteLength;
String get quoteChar => identical(quote, $DQ) ? '"' : "'";
int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount;
int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1;
- static StringQuoting getQuoting(int quote, bool raw, int quoteLength) {
- int index = quoteLength - 1;
- if (quoteLength > 2) index -= 1;
- return mapping[(raw ? 1 : 0) + index * 2 + (identical(quote, $SQ) ? 8 : 0)];
+ static StringQuoting getQuoting(int quote, bool raw, int leftQuoteLength) {
+ int quoteKindOffset = (quote == $DQ) ? 2 : 0;
+ int rawOffset = raw ? 1 : 0;
+ int index = (leftQuoteLength - 1) * 4 + rawOffset + quoteKindOffset;
+ if (index < _mapping.length) return _mapping[index];
+ return new StringQuoting(quote, raw: raw, leftQuoteLength: leftQuoteLength);
}
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/string_validator.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698