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

Side by Side Diff: pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart

Issue 2895803002: add fasta.scanner support for lazy assignment operators (Closed)
Patch Set: address comments Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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
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 // TODO(paulberry): once lazyAssignmentOperators are fully supported by
41 // Dart, remove this flag.
42 bool scanLazyAssignmentOperators = false;
ahe 2017/05/22 11:37:38 Why are we adding this flag?
danrubel 2017/05/23 11:33:40 AFAIK, the language does not yet support lazy assi
ahe 2017/05/23 11:46:08 I don't think the flag is necessary. The parser wi
43
44 /**
37 * The string offset for the next token that will be created. 45 * The string offset for the next token that will be created.
38 * 46 *
39 * Note that in the [Utf8BytesScanner], [stringOffset] and [scanOffset] values 47 * Note that in the [Utf8BytesScanner], [stringOffset] and [scanOffset] values
40 * are different. One string character can be encoded using multiple UTF-8 48 * are different. One string character can be encoded using multiple UTF-8
41 * bytes. 49 * bytes.
42 */ 50 */
43 int tokenStart = -1; 51 int tokenStart = -1;
44 52
45 /** 53 /**
46 * A pointer to the token stream created by this scanner. The first token 54 * A pointer to the token stream created by this scanner. The first token
(...skipping 17 matching lines...) Expand all
64 CommentToken comments; 72 CommentToken comments;
65 73
66 /** 74 /**
67 * A pointer to the last scanned comment token or `null` if none. 75 * A pointer to the last scanned comment token or `null` if none.
68 */ 76 */
69 Token commentsTail; 77 Token commentsTail;
70 78
71 final List<int> lineStarts; 79 final List<int> lineStarts;
72 80
73 AbstractScanner(this.includeComments, this.scanGenericMethodComments, 81 AbstractScanner(this.includeComments, this.scanGenericMethodComments,
82 this.scanLazyAssignmentOperators,
74 {int numberOfBytesHint}) 83 {int numberOfBytesHint})
75 : lineStarts = new LineStarts(numberOfBytesHint) { 84 : lineStarts = new LineStarts(numberOfBytesHint) {
76 this.tail = this.tokens; 85 this.tail = this.tokens;
77 } 86 }
78 87
79 /** 88 /**
80 * Advances and returns the next character. 89 * Advances and returns the next character.
81 * 90 *
82 * If the next character is non-ASCII, then the returned value depends on the 91 * If the next character is non-ASCII, then the returned value depends on the
83 * scanner implementation. The [Utf8BytesScanner] returns a UTF-8 byte, while 92 * scanner implementation. The [Utf8BytesScanner] returns a UTF-8 byte, while
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } else if (identical(next, $PERIOD)) { 488 } else if (identical(next, $PERIOD)) {
480 appendPrecedenceToken(TokenType.QUESTION_PERIOD); 489 appendPrecedenceToken(TokenType.QUESTION_PERIOD);
481 return advance(); 490 return advance();
482 } else { 491 } else {
483 appendPrecedenceToken(TokenType.QUESTION); 492 appendPrecedenceToken(TokenType.QUESTION);
484 return next; 493 return next;
485 } 494 }
486 } 495 }
487 496
488 int tokenizeBar(int next) { 497 int tokenizeBar(int next) {
489 // | || |= 498 // | || |= ||=
490 next = advance(); 499 next = advance();
491 if (identical(next, $BAR)) { 500 if (identical(next, $BAR)) {
501 next = advance();
502 if (scanLazyAssignmentOperators && identical(next, $EQ)) {
503 appendPrecedenceToken(TokenType.BAR_BAR_EQ);
504 return advance();
505 }
492 appendPrecedenceToken(TokenType.BAR_BAR); 506 appendPrecedenceToken(TokenType.BAR_BAR);
493 return advance(); 507 return next;
494 } else if (identical(next, $EQ)) { 508 } else if (identical(next, $EQ)) {
495 appendPrecedenceToken(TokenType.BAR_EQ); 509 appendPrecedenceToken(TokenType.BAR_EQ);
496 return advance(); 510 return advance();
497 } else { 511 } else {
498 appendPrecedenceToken(TokenType.BAR); 512 appendPrecedenceToken(TokenType.BAR);
499 return next; 513 return next;
500 } 514 }
501 } 515 }
502 516
503 int tokenizeAmpersand(int next) { 517 int tokenizeAmpersand(int next) {
504 // && &= & 518 // && &= & &&=
505 next = advance(); 519 next = advance();
506 if (identical(next, $AMPERSAND)) { 520 if (identical(next, $AMPERSAND)) {
521 next = advance();
522 if (scanLazyAssignmentOperators && identical(next, $EQ)) {
523 appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND_EQ);
524 return advance();
525 }
507 appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND); 526 appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND);
508 return advance(); 527 return next;
509 } else if (identical(next, $EQ)) { 528 } else if (identical(next, $EQ)) {
510 appendPrecedenceToken(TokenType.AMPERSAND_EQ); 529 appendPrecedenceToken(TokenType.AMPERSAND_EQ);
511 return advance(); 530 return advance();
512 } else { 531 } else {
513 appendPrecedenceToken(TokenType.AMPERSAND); 532 appendPrecedenceToken(TokenType.AMPERSAND);
514 return next; 533 return next;
515 } 534 }
516 } 535 }
517 536
518 int tokenizePercent(int next) { 537 int tokenizePercent(int next) {
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 switchToUint32(newLength); 1307 switchToUint32(newLength);
1289 } 1308 }
1290 } 1309 }
1291 1310
1292 void switchToUint32(int newLength) { 1311 void switchToUint32(int newLength) {
1293 final newArray = new Uint32List(newLength); 1312 final newArray = new Uint32List(newLength);
1294 newArray.setRange(0, arrayLength, array); 1313 newArray.setRange(0, arrayLength, array);
1295 array = newArray; 1314 array = newArray;
1296 } 1315 }
1297 } 1316 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner.dart ('k') | pkg/front_end/lib/src/fasta/scanner/array_based_scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698