| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 fasta.scanner.array_based_scanner; | 5 library fasta.scanner.array_based_scanner; |
| 6 | 6 |
| 7 import 'error_token.dart' show ErrorToken; | 7 import 'error_token.dart' show ErrorToken, UnmatchedToken; |
| 8 | 8 |
| 9 import 'keyword.dart' show Keyword; | 9 import 'keyword.dart' show Keyword; |
| 10 | 10 |
| 11 import 'precedence.dart' show PrecedenceInfo; | 11 import 'precedence.dart' show PrecedenceInfo; |
| 12 | 12 |
| 13 import 'token.dart' | 13 import 'token.dart' |
| 14 show | 14 show |
| 15 BeginGroupToken, | 15 BeginGroupToken, |
| 16 CommentToken, | 16 CommentToken, |
| 17 DartDocToken, | 17 DartDocToken, |
| 18 KeywordToken, | 18 KeywordToken, |
| 19 StringToken, | 19 StringToken, |
| 20 SymbolToken, | 20 SymbolToken, |
| 21 SyntheticSymbolToken, |
| 21 Token; | 22 Token; |
| 22 | 23 |
| 23 import 'token_constants.dart' | 24 import 'token_constants.dart' |
| 24 show | 25 show |
| 25 LT_TOKEN, | 26 LT_TOKEN, |
| 26 OPEN_CURLY_BRACKET_TOKEN, | 27 OPEN_CURLY_BRACKET_TOKEN, |
| 27 OPEN_PAREN_TOKEN, | 28 OPEN_PAREN_TOKEN, |
| 28 STRING_INTERPOLATION_TOKEN; | 29 STRING_INTERPOLATION_TOKEN; |
| 29 | 30 |
| 30 import 'characters.dart' show $LF, $STX; | 31 import 'characters.dart' show $LF, $STX; |
| 31 | 32 |
| 32 import 'abstract_scanner.dart' show AbstractScanner; | 33 import 'abstract_scanner.dart' show AbstractScanner, closeBraceInfoFor; |
| 33 | 34 |
| 34 import '../util/link.dart' show Link; | 35 import '../util/link.dart' show Link; |
| 35 | 36 |
| 36 abstract class ArrayBasedScanner extends AbstractScanner { | 37 abstract class ArrayBasedScanner extends AbstractScanner { |
| 37 bool hasErrors = false; | 38 bool hasErrors = false; |
| 38 | 39 |
| 39 ArrayBasedScanner(bool includeComments, {int numberOfBytesHint}) | 40 ArrayBasedScanner(bool includeComments, {int numberOfBytesHint}) |
| 40 : super(includeComments, numberOfBytesHint: numberOfBytesHint); | 41 : super(includeComments, numberOfBytesHint: numberOfBytesHint); |
| 41 | 42 |
| 42 /** | 43 /** |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 * In other words, this method is called when the scanner recognizes | 313 * In other words, this method is called when the scanner recognizes |
| 313 * something which cannot possibly be part of a type parameter/argument | 314 * something which cannot possibly be part of a type parameter/argument |
| 314 * list, like the '=' in the above example. | 315 * list, like the '=' in the above example. |
| 315 */ | 316 */ |
| 316 void discardOpenLt() { | 317 void discardOpenLt() { |
| 317 while (!groupingStack.isEmpty && | 318 while (!groupingStack.isEmpty && |
| 318 identical(groupingStack.head.kind, LT_TOKEN)) { | 319 identical(groupingStack.head.kind, LT_TOKEN)) { |
| 319 groupingStack = groupingStack.tail; | 320 groupingStack = groupingStack.tail; |
| 320 } | 321 } |
| 321 } | 322 } |
| 323 |
| 324 void unmatchedBeginGroup(BeginGroupToken begin) { |
| 325 // We want to ensure that unmatched BeginGroupTokens are reported as |
| 326 // errors. However, the diet parser assumes that groups are well-balanced |
| 327 // and will never look at the endGroup token. This is a nice property that |
| 328 // allows us to skip quickly over correct code. By inserting an additional |
| 329 // synthetic token in the stream, we can keep ignoring endGroup tokens. |
| 330 // |
| 331 // [begin] --next--> [tail] |
| 332 // [begin] --endG--> [synthetic] --next--> [next] --next--> [tail] |
| 333 // |
| 334 // This allows the diet parser to skip from [begin] via endGroup to |
| 335 // [synthetic] and ignore the [synthetic] token (assuming it's correct), |
| 336 // then the error will be reported when parsing the [next] token. |
| 337 // |
| 338 // For example, tokenize("{[1};") produces: |
| 339 // |
| 340 // SymbolToken({) --endGroup------------------------+ |
| 341 // | | |
| 342 // next | |
| 343 // v | |
| 344 // SymbolToken([) --endGroup--+ | |
| 345 // | | | |
| 346 // next | | |
| 347 // v | | |
| 348 // StringToken(1) | | |
| 349 // | | | |
| 350 // next | | |
| 351 // v | | |
| 352 // SymbolToken(])<------------+ <-- Synthetic token | |
| 353 // | | |
| 354 // next | |
| 355 // v | |
| 356 // UnmatchedToken([) | |
| 357 // | | |
| 358 // next | |
| 359 // v | |
| 360 // SymbolToken(})<----------------------------------+ |
| 361 // | |
| 362 // next |
| 363 // v |
| 364 // SymbolToken(;) |
| 365 // | |
| 366 // next |
| 367 // v |
| 368 // EOF |
| 369 PrecedenceInfo info = closeBraceInfoFor(begin); |
| 370 appendToken(new SyntheticSymbolToken(info, tokenStart)); |
| 371 begin.endGroup = tail; |
| 372 appendErrorToken(new UnmatchedToken(begin)); |
| 373 } |
| 322 } | 374 } |
| OLD | NEW |