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

Side by Side Diff: pkg/analyzer/lib/src/fasta/token_utils.dart

Issue 2799133003: enhance analyzer to parse uppercase and built-in/pseudo keywords (Closed)
Patch Set: 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
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 library fasta.analyzer.token_utils; 5 library fasta.analyzer.token_utils;
6 6
7 import 'package:front_end/src/fasta/scanner/error_token.dart' show ErrorToken; 7 import 'package:front_end/src/fasta/scanner/error_token.dart' show ErrorToken;
8 8
9 import 'package:front_end/src/fasta/scanner/keyword.dart' show Keyword; 9 import 'package:front_end/src/fasta/scanner/keyword.dart' show Keyword;
10 10
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 488
489 case IDENTIFIER_TOKEN: 489 case IDENTIFIER_TOKEN:
490 return makeStringToken(TokenType.IDENTIFIER); 490 return makeStringToken(TokenType.IDENTIFIER);
491 491
492 case INT_TOKEN: 492 case INT_TOKEN:
493 return makeStringToken(TokenType.INT); 493 return makeStringToken(TokenType.INT);
494 494
495 case KEYWORD_TOKEN: 495 case KEYWORD_TOKEN:
496 KeywordToken keywordToken = token; 496 KeywordToken keywordToken = token;
497 var syntax = keywordToken.keyword.syntax; 497 var syntax = keywordToken.keyword.syntax;
498 if (keywordToken.keyword.isPseudo) {
499 // TODO(paulberry,ahe): Fasta considers "deferred" be a "pseudo-keyword"
500 // (ordinary identifier which has special meaning under circumstances),
501 // but analyzer and the spec consider it to be a built-in identifier
502 // (identifier which can't be used in type names).
503 if (!identical(syntax, 'deferred')) {
504 return makeStringToken(TokenType.IDENTIFIER);
505 }
506 }
507 // TODO(paulberry): if the map lookup proves to be too slow, consider 498 // TODO(paulberry): if the map lookup proves to be too slow, consider
508 // using a switch statement, or perhaps a string of 499 // using a switch statement, or perhaps a string of
509 // "if (identical(syntax, "foo"))" checks. (Note that identical checks 500 // "if (identical(syntax, "foo"))" checks. (Note that identical checks
510 // should be safe because the Fasta scanner uses string literals for 501 // should be safe because the Fasta scanner uses string literals for
511 // the values of keyword.syntax.) 502 // the values of keyword.syntax.)
512 var keyword = 503 var keyword =
513 _keywordMap[syntax] ?? internalError('Unknown keyword: $syntax'); 504 _keywordMap[syntax] ?? internalError('Unknown keyword: $syntax');
514 if (commentToken == null) { 505 if (commentToken == null) {
515 return new analyzer.KeywordToken(keyword, token.charOffset); 506 return new analyzer.KeywordToken(keyword, token.charOffset);
516 } else { 507 } else {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 "super": analyzer.Keyword.SUPER, 559 "super": analyzer.Keyword.SUPER,
569 "switch": analyzer.Keyword.SWITCH, 560 "switch": analyzer.Keyword.SWITCH,
570 "this": analyzer.Keyword.THIS, 561 "this": analyzer.Keyword.THIS,
571 "throw": analyzer.Keyword.THROW, 562 "throw": analyzer.Keyword.THROW,
572 "true": analyzer.Keyword.TRUE, 563 "true": analyzer.Keyword.TRUE,
573 "try": analyzer.Keyword.TRY, 564 "try": analyzer.Keyword.TRY,
574 "var": analyzer.Keyword.VAR, 565 "var": analyzer.Keyword.VAR,
575 "void": analyzer.Keyword.VOID, 566 "void": analyzer.Keyword.VOID,
576 "while": analyzer.Keyword.WHILE, 567 "while": analyzer.Keyword.WHILE,
577 "with": analyzer.Keyword.WITH, 568 "with": analyzer.Keyword.WITH,
569 //
578 "is": analyzer.Keyword.IS, 570 "is": analyzer.Keyword.IS,
571 //
579 "abstract": analyzer.Keyword.ABSTRACT, 572 "abstract": analyzer.Keyword.ABSTRACT,
580 "as": analyzer.Keyword.AS, 573 "as": analyzer.Keyword.AS,
581 "covariant": analyzer.Keyword.COVARIANT, 574 "covariant": analyzer.Keyword.COVARIANT,
575 "deferred": analyzer.Keyword.DEFERRED,
582 "dynamic": analyzer.Keyword.DYNAMIC, 576 "dynamic": analyzer.Keyword.DYNAMIC,
583 "export": analyzer.Keyword.EXPORT, 577 "export": analyzer.Keyword.EXPORT,
584 "external": analyzer.Keyword.EXTERNAL, 578 "external": analyzer.Keyword.EXTERNAL,
585 "factory": analyzer.Keyword.FACTORY, 579 "factory": analyzer.Keyword.FACTORY,
586 "get": analyzer.Keyword.GET, 580 "get": analyzer.Keyword.GET,
587 "implements": analyzer.Keyword.IMPLEMENTS, 581 "implements": analyzer.Keyword.IMPLEMENTS,
588 "import": analyzer.Keyword.IMPORT, 582 "import": analyzer.Keyword.IMPORT,
589 "library": analyzer.Keyword.LIBRARY, 583 "library": analyzer.Keyword.LIBRARY,
590 "operator": analyzer.Keyword.OPERATOR, 584 "operator": analyzer.Keyword.OPERATOR,
591 "part": analyzer.Keyword.PART, 585 "part": analyzer.Keyword.PART,
592 "set": analyzer.Keyword.SET, 586 "set": analyzer.Keyword.SET,
593 "static": analyzer.Keyword.STATIC, 587 "static": analyzer.Keyword.STATIC,
594 "typedef": analyzer.Keyword.TYPEDEF, 588 "typedef": analyzer.Keyword.TYPEDEF,
595 "deferred": analyzer.Keyword.DEFERRED, 589 //
590 "async": analyzer.Keyword.ASYNC,
591 "await": analyzer.Keyword.AWAIT,
592 "Function": analyzer.Keyword.FUNCTION,
593 "hide": analyzer.Keyword.HIDE,
594 "native": analyzer.Keyword.NATIVE,
595 "of": analyzer.Keyword.OF,
596 "on": analyzer.Keyword.ON,
597 "patch": analyzer.Keyword.PATCH,
598 "show": analyzer.Keyword.SHOW,
599 "source": analyzer.Keyword.SOURCE,
600 "sync": analyzer.Keyword.SYNC,
601 "yield": analyzer.Keyword.YIELD,
596 }; 602 };
597 603
598 TokenType getTokenType(Token token) { 604 TokenType getTokenType(Token token) {
599 switch (token.kind) { 605 switch (token.kind) {
600 case EOF_TOKEN: 606 case EOF_TOKEN:
601 return TokenType.EOF; 607 return TokenType.EOF;
602 case DOUBLE_TOKEN: 608 case DOUBLE_TOKEN:
603 return TokenType.DOUBLE; 609 return TokenType.DOUBLE;
604 case HEXADECIMAL_TOKEN: 610 case HEXADECIMAL_TOKEN:
605 return TokenType.HEXADECIMAL; 611 return TokenType.HEXADECIMAL;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 case PERIOD_PERIOD_PERIOD_TOKEN: 745 case PERIOD_PERIOD_PERIOD_TOKEN:
740 return TokenType.PERIOD_PERIOD_PERIOD; 746 return TokenType.PERIOD_PERIOD_PERIOD;
741 case GENERIC_METHOD_TYPE_LIST_TOKEN: 747 case GENERIC_METHOD_TYPE_LIST_TOKEN:
742 return TokenType.GENERIC_METHOD_TYPE_LIST; 748 return TokenType.GENERIC_METHOD_TYPE_LIST;
743 case GENERIC_METHOD_TYPE_ASSIGN_TOKEN: 749 case GENERIC_METHOD_TYPE_ASSIGN_TOKEN:
744 return TokenType.GENERIC_METHOD_TYPE_ASSIGN; 750 return TokenType.GENERIC_METHOD_TYPE_ASSIGN;
745 default: 751 default:
746 return internalError("Unhandled token ${token.info}"); 752 return internalError("Unhandled token ${token.info}");
747 } 753 }
748 } 754 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/error_verifier.dart » ('j') | pkg/analyzer/lib/src/generated/error_verifier.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698