OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.abstract_scanner; | 5 library fasta.scanner.abstract_scanner; |
6 | 6 |
7 import 'dart:collection' show ListMixin; | 7 import 'dart:collection' show ListMixin; |
8 | 8 |
9 import 'dart:typed_data' show Uint16List, Uint32List; | 9 import 'dart:typed_data' show Uint16List, Uint32List; |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 abstract class AbstractScanner implements Scanner { | 27 abstract class AbstractScanner implements Scanner { |
28 final bool includeComments; | 28 final bool includeComments; |
29 | 29 |
30 /** | 30 /** |
31 * A flag indicating whether to parse generic method comments, of the form | 31 * A flag indicating whether to parse generic method comments, of the form |
32 * `/*=T*/` and `/*<T>*/`. The flag [includeComments] must be set to `true`. | 32 * `/*=T*/` and `/*<T>*/`. The flag [includeComments] must be set to `true`. |
33 */ | 33 */ |
34 bool scanGenericMethodComments = false; | 34 bool scanGenericMethodComments = false; |
35 | 35 |
36 /** | 36 /** |
| 37 * A flag indicating whether the lazy compound assignment operators '&&=' and |
| 38 * '||=' are enabled. |
| 39 */ |
| 40 bool scanLazyAssignmentOperators = false; |
| 41 |
| 42 /** |
37 * The string offset for the next token that will be created. | 43 * The string offset for the next token that will be created. |
38 * | 44 * |
39 * Note that in the [Utf8BytesScanner], [stringOffset] and [scanOffset] values | 45 * Note that in the [Utf8BytesScanner], [stringOffset] and [scanOffset] values |
40 * are different. One string character can be encoded using multiple UTF-8 | 46 * are different. One string character can be encoded using multiple UTF-8 |
41 * bytes. | 47 * bytes. |
42 */ | 48 */ |
43 int tokenStart = -1; | 49 int tokenStart = -1; |
44 | 50 |
45 /** | 51 /** |
46 * A pointer to the token stream created by this scanner. The first token | 52 * A pointer to the token stream created by this scanner. The first token |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 } else if (identical(next, $PERIOD)) { | 485 } else if (identical(next, $PERIOD)) { |
480 appendPrecedenceToken(TokenType.QUESTION_PERIOD); | 486 appendPrecedenceToken(TokenType.QUESTION_PERIOD); |
481 return advance(); | 487 return advance(); |
482 } else { | 488 } else { |
483 appendPrecedenceToken(TokenType.QUESTION); | 489 appendPrecedenceToken(TokenType.QUESTION); |
484 return next; | 490 return next; |
485 } | 491 } |
486 } | 492 } |
487 | 493 |
488 int tokenizeBar(int next) { | 494 int tokenizeBar(int next) { |
489 // | || |= | 495 // | || |= ||= |
490 next = advance(); | 496 next = advance(); |
491 if (identical(next, $BAR)) { | 497 if (identical(next, $BAR)) { |
| 498 next = advance(); |
| 499 if (scanLazyAssignmentOperators && identical(next, $EQ)) { |
| 500 appendPrecedenceToken(TokenType.BAR_BAR_EQ); |
| 501 return advance(); |
| 502 } |
492 appendPrecedenceToken(TokenType.BAR_BAR); | 503 appendPrecedenceToken(TokenType.BAR_BAR); |
493 return advance(); | 504 return next; |
494 } else if (identical(next, $EQ)) { | 505 } else if (identical(next, $EQ)) { |
495 appendPrecedenceToken(TokenType.BAR_EQ); | 506 appendPrecedenceToken(TokenType.BAR_EQ); |
496 return advance(); | 507 return advance(); |
497 } else { | 508 } else { |
498 appendPrecedenceToken(TokenType.BAR); | 509 appendPrecedenceToken(TokenType.BAR); |
499 return next; | 510 return next; |
500 } | 511 } |
501 } | 512 } |
502 | 513 |
503 int tokenizeAmpersand(int next) { | 514 int tokenizeAmpersand(int next) { |
504 // && &= & | 515 // && &= & &&= |
505 next = advance(); | 516 next = advance(); |
506 if (identical(next, $AMPERSAND)) { | 517 if (identical(next, $AMPERSAND)) { |
| 518 next = advance(); |
| 519 if (scanLazyAssignmentOperators && identical(next, $EQ)) { |
| 520 appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND_EQ); |
| 521 return advance(); |
| 522 } |
507 appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND); | 523 appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND); |
508 return advance(); | 524 return next; |
509 } else if (identical(next, $EQ)) { | 525 } else if (identical(next, $EQ)) { |
510 appendPrecedenceToken(TokenType.AMPERSAND_EQ); | 526 appendPrecedenceToken(TokenType.AMPERSAND_EQ); |
511 return advance(); | 527 return advance(); |
512 } else { | 528 } else { |
513 appendPrecedenceToken(TokenType.AMPERSAND); | 529 appendPrecedenceToken(TokenType.AMPERSAND); |
514 return next; | 530 return next; |
515 } | 531 } |
516 } | 532 } |
517 | 533 |
518 int tokenizePercent(int next) { | 534 int tokenizePercent(int next) { |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 switchToUint32(newLength); | 1304 switchToUint32(newLength); |
1289 } | 1305 } |
1290 } | 1306 } |
1291 | 1307 |
1292 void switchToUint32(int newLength) { | 1308 void switchToUint32(int newLength) { |
1293 final newArray = new Uint32List(newLength); | 1309 final newArray = new Uint32List(newLength); |
1294 newArray.setRange(0, arrayLength, array); | 1310 newArray.setRange(0, arrayLength, array); |
1295 array = newArray; | 1311 array = newArray; |
1296 } | 1312 } |
1297 } | 1313 } |
OLD | NEW |