Chromium Code Reviews| 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); |
| +} |