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

Unified Diff: pkg/front_end/lib/src/fasta/analyzer/token_utils.dart

Issue 2686293002: Use Keyword.isPseudo to translate Fasta's "pseudo-keywords" properly. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/front_end/test/scanner_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/analyzer/token_utils.dart
diff --git a/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart b/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart
index c1b14c1e37da0f8bad18e8f89fcfd7fd57e30c17..cd0fb140b86ba2dc5b5114fb1f98dd2af0d59e99 100644
--- a/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart
+++ b/pkg/front_end/lib/src/fasta/analyzer/token_utils.dart
@@ -54,22 +54,22 @@ analyzer.Token toAnalyzerToken(Token token,
case KEYWORD_TOKEN:
KeywordToken keywordToken = token;
var syntax = keywordToken.keyword.syntax;
+ if (keywordToken.keyword.isPseudo) {
+ // TODO(paulberry,ahe): Fasta considers "deferred" be a "pseudo-keyword"
+ // (ordinary identifier which has special meaning under circumstances),
+ // but analyzer and the spec consider it to be a built-in identifier
+ // (identifier which can't be used in type names).
+ if (!identical(syntax, 'deferred')) {
+ return makeStringToken(TokenType.IDENTIFIER);
+ }
+ }
// TODO(paulberry): if the map lookup proves to be too slow, consider
// using a switch statement, or perhaps a string of
// "if (identical(syntax, "foo"))" checks. (Note that identical checks
// should be safe because the Fasta scanner uses string literals for
// the values of keyword.syntax.)
- var keyword = _keywordMap[syntax];
- if (keyword == null) {
- if (_pseudoKeywords.contains(syntax)) {
- // TODO(paulberry,ahe): fasta scans "async", "await", and "sync" as
- // keywords. They need to be identifiers since their meaning is only
- // special in certain contexts.
- return makeStringToken(TokenType.IDENTIFIER);
- } else {
- return internalError('Unknown keyword: $syntax');
- }
- }
+ var keyword =
+ _keywordMap[syntax] ?? internalError('Unknown keyword: $syntax');
if (commentToken == null) {
return new analyzer.KeywordToken(keyword, token.charOffset);
} else {
@@ -145,8 +145,6 @@ final _keywordMap = {
"deferred": analyzer.Keyword.DEFERRED,
};
-final _pseudoKeywords = new Set<String>.from(['async', 'await', 'sync']);
-
TokenType getTokenType(Token token) {
switch (token.kind) {
case EOF_TOKEN: return TokenType.EOF;
« no previous file with comments | « no previous file | pkg/front_end/test/scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698