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

Unified Diff: dart/site/try/src/interaction_manager.dart

Issue 373563002: Handle multiline interpolated strings in line-based scanner. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | « no previous file | dart/site/try/src/selection.dart » ('j') | dart/tests/try/paste_content_rewriting_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/site/try/src/interaction_manager.dart
diff --git a/dart/site/try/src/interaction_manager.dart b/dart/site/try/src/interaction_manager.dart
index 97c06d460eef977fa048c39183e68c80448643bf..903763965ab25ab03437748eea12e607ec74689e 100644
--- a/dart/site/try/src/interaction_manager.dart
+++ b/dart/site/try/src/interaction_manager.dart
@@ -25,6 +25,9 @@ import 'package:compiler/implementation/scanner/scannerlib.dart' show
BeginGroupToken,
EOF_TOKEN,
ErrorToken,
+ STRING_INTERPOLATION_IDENTIFIER_TOKEN,
+ STRING_INTERPOLATION_TOKEN,
+ STRING_TOKEN,
StringScanner,
Token,
UnmatchedToken,
@@ -33,6 +36,12 @@ import 'package:compiler/implementation/scanner/scannerlib.dart' show
import 'package:compiler/implementation/source_file.dart' show
StringSourceFile;
+import 'package:compiler/implementation/string_validator.dart' show
+ StringValidator;
+
+import 'package:compiler/implementation/tree/tree.dart' show
+ StringQuoting;
+
import 'compilation.dart' show
currentSource,
startCompilation;
@@ -1135,6 +1144,14 @@ String tokenizeAndHighlight(String line,
if (token is BeginGroupToken && token.endGroup != null) {
follow = token.endGroup.next;
}
+ if (token.kind == STRING_TOKEN) {
+ follow = followString(follow);
+ if (follow is UnmatchedToken) {
+ if ('${follow.begin.value}' == r'${') {
+ newState += '${extractQuote(token.value)}';
+ }
+ }
+ }
if (follow is ErrorToken && follow.charOffset == token.charOffset) {
if (follow is UnmatchedToken) {
newState += '${follow.begin.value}';
@@ -1282,3 +1299,33 @@ void workAroundFirefoxBug() {
'${selection.anchorNode}@${selection.anchorOffset}.');
}
}
+
+/// Compute the token following a string. Compare to parseSingleLiteralString
+/// in parser.dart.
+Token followString(Token token) {
+ // TODO(ahe): I should be able to get rid of this if I change the scanner to
+ // create BeginGroupToken for strings.
+ int kind = token.kind;
+ while (kind != EOF_TOKEN) {
+ if (kind == STRING_INTERPOLATION_TOKEN) {
+ // Looking at ${expression}.
+ BeginGroupToken begin = token;
+ token = begin.endGroup.next;
+ } else if (kind == STRING_INTERPOLATION_IDENTIFIER_TOKEN) {
+ // Looking at $identifier.
kasperl 2014/07/07 11:16:39 So token is $ and token.next is the identifier and
ahe 2014/07/09 10:11:13 Good catch!
+ token = token.next.next.next;
+ } else {
+ return token;
+ }
+ kind = token.kind;
+ if (kind != STRING_TOKEN) return token;
+ token = token.next;
+ kind = token.kind;
+ }
+ return token;
+}
+
+String extractQuote(String string) {
kasperl 2014/07/07 11:16:39 Would this fit better in the StringQuoting impleme
ahe 2014/07/09 10:11:13 Perhaps, but dart2js wouldn't use it.
+ StringQuoting q = StringValidator.quotingFromString(string);
+ return (q.raw ? 'r' : '') + (q.quoteChar * q.leftQuoteLength);
+}
« no previous file with comments | « no previous file | dart/site/try/src/selection.dart » ('j') | dart/tests/try/paste_content_rewriting_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698