Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library trydart.interaction_manager; | 5 library trydart.interaction_manager; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'dart:convert' show | 9 import 'dart:convert' show |
| 10 JSON; | 10 JSON; |
| 11 | 11 |
| 12 import 'dart:math' show | 12 import 'dart:math' show |
| 13 max, | 13 max, |
| 14 min; | 14 min; |
| 15 | 15 |
| 16 import 'dart:async' show | 16 import 'dart:async' show |
| 17 Completer, | 17 Completer, |
| 18 Future, | 18 Future, |
| 19 Timer; | 19 Timer; |
| 20 | 20 |
| 21 import 'dart:collection' show | 21 import 'dart:collection' show |
| 22 Queue; | 22 Queue; |
| 23 | 23 |
| 24 import 'package:compiler/implementation/scanner/scannerlib.dart' show | 24 import 'package:compiler/implementation/scanner/scannerlib.dart' show |
| 25 BeginGroupToken, | 25 BeginGroupToken, |
| 26 EOF_TOKEN, | 26 EOF_TOKEN, |
| 27 ErrorToken, | 27 ErrorToken, |
| 28 STRING_INTERPOLATION_IDENTIFIER_TOKEN, | |
| 29 STRING_INTERPOLATION_TOKEN, | |
| 30 STRING_TOKEN, | |
| 28 StringScanner, | 31 StringScanner, |
| 29 Token, | 32 Token, |
| 30 UnmatchedToken, | 33 UnmatchedToken, |
| 31 UnterminatedToken; | 34 UnterminatedToken; |
| 32 | 35 |
| 33 import 'package:compiler/implementation/source_file.dart' show | 36 import 'package:compiler/implementation/source_file.dart' show |
| 34 StringSourceFile; | 37 StringSourceFile; |
| 35 | 38 |
| 39 import 'package:compiler/implementation/string_validator.dart' show | |
| 40 StringValidator; | |
| 41 | |
| 42 import 'package:compiler/implementation/tree/tree.dart' show | |
| 43 StringQuoting; | |
| 44 | |
| 36 import 'compilation.dart' show | 45 import 'compilation.dart' show |
| 37 currentSource, | 46 currentSource, |
| 38 startCompilation; | 47 startCompilation; |
| 39 | 48 |
| 40 import 'ui.dart' show | 49 import 'ui.dart' show |
| 41 currentTheme, | 50 currentTheme, |
| 42 hackDiv, | 51 hackDiv, |
| 43 mainEditorPane, | 52 mainEditorPane, |
| 44 observer, | 53 observer, |
| 45 outputDiv, | 54 outputDiv, |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 | 1137 |
| 1129 Token tokenToDecorate = token; | 1138 Token tokenToDecorate = token; |
| 1130 if (token is UnterminatedToken && isUnterminatedMultiLineToken(token)) { | 1139 if (token is UnterminatedToken && isUnterminatedMultiLineToken(token)) { |
| 1131 newState += '${token.start}'; | 1140 newState += '${token.start}'; |
| 1132 continue; // This might not be an error. | 1141 continue; // This might not be an error. |
| 1133 } else { | 1142 } else { |
| 1134 Token follow = token.next; | 1143 Token follow = token.next; |
| 1135 if (token is BeginGroupToken && token.endGroup != null) { | 1144 if (token is BeginGroupToken && token.endGroup != null) { |
| 1136 follow = token.endGroup.next; | 1145 follow = token.endGroup.next; |
| 1137 } | 1146 } |
| 1147 if (token.kind == STRING_TOKEN) { | |
| 1148 follow = followString(follow); | |
| 1149 if (follow is UnmatchedToken) { | |
| 1150 if ('${follow.begin.value}' == r'${') { | |
| 1151 newState += '${extractQuote(token.value)}'; | |
| 1152 } | |
| 1153 } | |
| 1154 } | |
| 1138 if (follow is ErrorToken && follow.charOffset == token.charOffset) { | 1155 if (follow is ErrorToken && follow.charOffset == token.charOffset) { |
| 1139 if (follow is UnmatchedToken) { | 1156 if (follow is UnmatchedToken) { |
| 1140 newState += '${follow.begin.value}'; | 1157 newState += '${follow.begin.value}'; |
| 1141 } else { | 1158 } else { |
| 1142 tokenToDecorate = follow; | 1159 tokenToDecorate = follow; |
| 1143 } | 1160 } |
| 1144 } | 1161 } |
| 1145 } | 1162 } |
| 1146 | 1163 |
| 1147 if (charOffset < offset) { | 1164 if (charOffset < offset) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1275 // Safari can also reach this code, but the offset isn't wrong, just | 1292 // Safari can also reach this code, but the offset isn't wrong, just |
| 1276 // inconsistent. After moving the cursor back and forth, Safari will make | 1293 // inconsistent. After moving the cursor back and forth, Safari will make |
| 1277 // the offset relative to a text node. | 1294 // the offset relative to a text node. |
| 1278 selection | 1295 selection |
| 1279 ..modify('move', 'backward', 'character') | 1296 ..modify('move', 'backward', 'character') |
| 1280 ..modify('move', 'forward', 'character'); | 1297 ..modify('move', 'forward', 'character'); |
| 1281 print('Selection adjusted $node@$offset -> ' | 1298 print('Selection adjusted $node@$offset -> ' |
| 1282 '${selection.anchorNode}@${selection.anchorOffset}.'); | 1299 '${selection.anchorNode}@${selection.anchorOffset}.'); |
| 1283 } | 1300 } |
| 1284 } | 1301 } |
| 1302 | |
| 1303 /// Compute the token following a string. Compare to parseSingleLiteralString | |
| 1304 /// in parser.dart. | |
| 1305 Token followString(Token token) { | |
| 1306 // TODO(ahe): I should be able to get rid of this if I change the scanner to | |
| 1307 // create BeginGroupToken for strings. | |
| 1308 int kind = token.kind; | |
| 1309 while (kind != EOF_TOKEN) { | |
| 1310 if (kind == STRING_INTERPOLATION_TOKEN) { | |
| 1311 // Looking at ${expression}. | |
| 1312 BeginGroupToken begin = token; | |
| 1313 token = begin.endGroup.next; | |
| 1314 } else if (kind == STRING_INTERPOLATION_IDENTIFIER_TOKEN) { | |
| 1315 // 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!
| |
| 1316 token = token.next.next.next; | |
| 1317 } else { | |
| 1318 return token; | |
| 1319 } | |
| 1320 kind = token.kind; | |
| 1321 if (kind != STRING_TOKEN) return token; | |
| 1322 token = token.next; | |
| 1323 kind = token.kind; | |
| 1324 } | |
| 1325 return token; | |
| 1326 } | |
| 1327 | |
| 1328 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.
| |
| 1329 StringQuoting q = StringValidator.quotingFromString(string); | |
| 1330 return (q.raw ? 'r' : '') + (q.quoteChar * q.leftQuoteLength); | |
| 1331 } | |
| OLD | NEW |