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

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

Issue 2842213003: new TokenType and Keyword API (Closed)
Patch Set: rebase Created 3 years, 8 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
« no previous file with comments | « pkg/front_end/lib/src/scanner/scanner.dart ('k') | pkg/front_end/test/scanner_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /** 5 /**
6 * Defines the tokens that are produced by the scanner, used by the parser, and 6 * Defines the tokens that are produced by the scanner, used by the parser, and
7 * referenced from the [AST structure](ast.dart). 7 * referenced from the [AST structure](ast.dart).
8 */ 8 */
9 import 'dart:collection'; 9 import 'dart:collection';
10 10
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 /** 373 /**
374 * A flag indicating whether the keyword can be used as an identifier 374 * A flag indicating whether the keyword can be used as an identifier
375 * in some situations. 375 * in some situations.
376 */ 376 */
377 final bool isPseudo; 377 final bool isPseudo;
378 378
379 /** 379 /**
380 * The lexeme for the keyword. 380 * The lexeme for the keyword.
381 */ 381 */
382 final String syntax; 382 final String lexeme;
383 383
384 /** 384 /**
385 * Initialize a newly created keyword. 385 * Initialize a newly created keyword.
386 */ 386 */
387 const Keyword(this.syntax, 387 const Keyword(this.lexeme,
388 {this.isBuiltIn: false, 388 {this.isBuiltIn: false,
389 this.isPseudo: false, 389 this.isPseudo: false,
390 this.info: TokenType.KEYWORD}); 390 this.info: TokenType.KEYWORD});
391 391
392 bool get isBuiltInOrPseudo => isBuiltIn || isPseudo; 392 bool get isBuiltInOrPseudo => isBuiltIn || isPseudo;
393 393
394 /** 394 /**
395 * A flag indicating whether the keyword is "built-in" identifier. 395 * A flag indicating whether the keyword is "built-in" identifier.
396 * This method exists for backward compatibility and will be removed. 396 * This method exists for backward compatibility and will be removed.
397 * Use [isBuiltIn] instead. 397 * Use [isBuiltIn] instead.
398 */ 398 */
399 @deprecated 399 @deprecated
400 bool get isPseudoKeyword => isBuiltIn; // TODO (danrubel): remove this 400 bool get isPseudoKeyword => isBuiltIn; // TODO (danrubel): remove this
401 401
402 /** 402 /**
403 * The name of the keyword type. 403 * The name of the keyword type.
404 */ 404 */
405 String get name => syntax.toUpperCase(); 405 String get name => lexeme.toUpperCase();
406
407 /**
408 * The lexeme for the keyword.
409 *
410 * Deprecated - use [lexeme] instead.
411 */
412 @deprecated
413 String get syntax => lexeme;
406 414
407 @override 415 @override
408 String toString() => name; 416 String toString() => name;
409 417
410 /** 418 /**
411 * Create a table mapping the lexemes of keywords to the corresponding keyword 419 * Create a table mapping the lexemes of keywords to the corresponding keyword
412 * and return the table that was created. 420 * and return the table that was created.
413 */ 421 */
414 static Map<String, Keyword> _createKeywordMap() { 422 static Map<String, Keyword> _createKeywordMap() {
415 LinkedHashMap<String, Keyword> result = 423 LinkedHashMap<String, Keyword> result =
416 new LinkedHashMap<String, Keyword>(); 424 new LinkedHashMap<String, Keyword>();
417 for (Keyword keyword in values) { 425 for (Keyword keyword in values) {
418 result[keyword.syntax] = keyword; 426 result[keyword.lexeme] = keyword;
419 } 427 }
420 return result; 428 return result;
421 } 429 }
422 } 430 }
423 431
424 /** 432 /**
425 * A token representing a keyword in the language. 433 * A token representing a keyword in the language.
426 */ 434 */
427 class KeywordToken extends SimpleToken { 435 class KeywordToken extends SimpleToken {
428 @override 436 @override
429 final Keyword keyword; 437 final Keyword keyword;
430 438
431 /** 439 /**
432 * Initialize a newly created token to represent the given [keyword] at the 440 * Initialize a newly created token to represent the given [keyword] at the
433 * given [offset]. 441 * given [offset].
434 */ 442 */
435 KeywordToken(this.keyword, int offset) : super(TokenType.KEYWORD, offset); 443 KeywordToken(this.keyword, int offset) : super(TokenType.KEYWORD, offset);
436 444
437 @override 445 @override
438 String get lexeme => keyword.syntax; 446 String get lexeme => keyword.lexeme;
439 447
440 @override 448 @override
441 Token copy() => new KeywordToken(keyword, offset); 449 Token copy() => new KeywordToken(keyword, offset);
442 450
443 @override 451 @override
444 // Changed return type from Keyword to Object because 452 // Changed return type from Keyword to Object because
445 // fasta considers pseudo-keywords to be keywords rather than identifiers 453 // fasta considers pseudo-keywords to be keywords rather than identifiers
446 Object value() => keyword; 454 Object value() => keyword;
447 } 455 }
448 456
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 bool get isEqualityOperator => 1478 bool get isEqualityOperator =>
1471 this == TokenType.BANG_EQ || this == TokenType.EQ_EQ; 1479 this == TokenType.BANG_EQ || this == TokenType.EQ_EQ;
1472 1480
1473 /** 1481 /**
1474 * Return `true` if this type of token represents an increment operator. 1482 * Return `true` if this type of token represents an increment operator.
1475 */ 1483 */
1476 bool get isIncrementOperator => 1484 bool get isIncrementOperator =>
1477 this == TokenType.PLUS_PLUS || this == TokenType.MINUS_MINUS; 1485 this == TokenType.PLUS_PLUS || this == TokenType.MINUS_MINUS;
1478 1486
1479 /** 1487 /**
1488 * Return `true` if this type of token is a keyword.
1489 */
1490 bool get isKeyword => kind == KEYWORD_TOKEN;
1491
1492 /**
1480 * Return `true` if this type of token represents a multiplicative operator. 1493 * Return `true` if this type of token represents a multiplicative operator.
1481 */ 1494 */
1482 bool get isMultiplicativeOperator => precedence == MULTIPLICATIVE_PRECEDENCE; 1495 bool get isMultiplicativeOperator => precedence == MULTIPLICATIVE_PRECEDENCE;
1483 1496
1484 /** 1497 /**
1485 * Return `true` if this type of token represents a relational operator. 1498 * Return `true` if this type of token represents a relational operator.
1486 */ 1499 */
1487 bool get isRelationalOperator => 1500 bool get isRelationalOperator =>
1488 this == TokenType.LT || 1501 this == TokenType.LT ||
1489 this == TokenType.LT_EQ || 1502 this == TokenType.LT_EQ ||
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 1555
1543 void set precedingComments(CommentToken comment) { 1556 void set precedingComments(CommentToken comment) {
1544 _precedingComment = comment; 1557 _precedingComment = comment;
1545 _setCommentParent(_precedingComment); 1558 _setCommentParent(_precedingComment);
1546 } 1559 }
1547 1560
1548 @override 1561 @override
1549 Token copy() => 1562 Token copy() =>
1550 new TokenWithComment(type, offset, copyComments(precedingComments)); 1563 new TokenWithComment(type, offset, copyComments(precedingComments));
1551 } 1564 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/scanner/scanner.dart ('k') | pkg/front_end/test/scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698