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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | 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 library fasta.analyzer.token_utils; 5 library fasta.analyzer.token_utils;
6 6
7 import 'package:front_end/src/fasta/scanner/token.dart' show 7 import 'package:front_end/src/fasta/scanner/token.dart' show
8 KeywordToken, 8 KeywordToken,
9 Token; 9 Token;
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 case IDENTIFIER_TOKEN: 48 case IDENTIFIER_TOKEN:
49 return makeStringToken(TokenType.IDENTIFIER); 49 return makeStringToken(TokenType.IDENTIFIER);
50 50
51 case INT_TOKEN: 51 case INT_TOKEN:
52 return makeStringToken(TokenType.INT); 52 return makeStringToken(TokenType.INT);
53 53
54 case KEYWORD_TOKEN: 54 case KEYWORD_TOKEN:
55 KeywordToken keywordToken = token; 55 KeywordToken keywordToken = token;
56 var syntax = keywordToken.keyword.syntax; 56 var syntax = keywordToken.keyword.syntax;
57 if (keywordToken.keyword.isPseudo) {
58 // TODO(paulberry,ahe): Fasta considers "deferred" be a "pseudo-keyword"
59 // (ordinary identifier which has special meaning under circumstances),
60 // but analyzer and the spec consider it to be a built-in identifier
61 // (identifier which can't be used in type names).
62 if (!identical(syntax, 'deferred')) {
63 return makeStringToken(TokenType.IDENTIFIER);
64 }
65 }
57 // TODO(paulberry): if the map lookup proves to be too slow, consider 66 // TODO(paulberry): if the map lookup proves to be too slow, consider
58 // using a switch statement, or perhaps a string of 67 // using a switch statement, or perhaps a string of
59 // "if (identical(syntax, "foo"))" checks. (Note that identical checks 68 // "if (identical(syntax, "foo"))" checks. (Note that identical checks
60 // should be safe because the Fasta scanner uses string literals for 69 // should be safe because the Fasta scanner uses string literals for
61 // the values of keyword.syntax.) 70 // the values of keyword.syntax.)
62 var keyword = _keywordMap[syntax]; 71 var keyword =
63 if (keyword == null) { 72 _keywordMap[syntax] ?? internalError('Unknown keyword: $syntax');
64 if (_pseudoKeywords.contains(syntax)) {
65 // TODO(paulberry,ahe): fasta scans "async", "await", and "sync" as
66 // keywords. They need to be identifiers since their meaning is only
67 // special in certain contexts.
68 return makeStringToken(TokenType.IDENTIFIER);
69 } else {
70 return internalError('Unknown keyword: $syntax');
71 }
72 }
73 if (commentToken == null) { 73 if (commentToken == null) {
74 return new analyzer.KeywordToken(keyword, token.charOffset); 74 return new analyzer.KeywordToken(keyword, token.charOffset);
75 } else { 75 } else {
76 return new analyzer.KeywordTokenWithComment( 76 return new analyzer.KeywordTokenWithComment(
77 keyword, token.charOffset, commentToken); 77 keyword, token.charOffset, commentToken);
78 } 78 }
79 break; 79 break;
80 80
81 case STRING_TOKEN: 81 case STRING_TOKEN:
82 return makeStringToken(TokenType.STRING); 82 return makeStringToken(TokenType.STRING);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 "import": analyzer.Keyword.IMPORT, 138 "import": analyzer.Keyword.IMPORT,
139 "library": analyzer.Keyword.LIBRARY, 139 "library": analyzer.Keyword.LIBRARY,
140 "operator": analyzer.Keyword.OPERATOR, 140 "operator": analyzer.Keyword.OPERATOR,
141 "part": analyzer.Keyword.PART, 141 "part": analyzer.Keyword.PART,
142 "set": analyzer.Keyword.SET, 142 "set": analyzer.Keyword.SET,
143 "static": analyzer.Keyword.STATIC, 143 "static": analyzer.Keyword.STATIC,
144 "typedef": analyzer.Keyword.TYPEDEF, 144 "typedef": analyzer.Keyword.TYPEDEF,
145 "deferred": analyzer.Keyword.DEFERRED, 145 "deferred": analyzer.Keyword.DEFERRED,
146 }; 146 };
147 147
148 final _pseudoKeywords = new Set<String>.from(['async', 'await', 'sync']);
149
150 TokenType getTokenType(Token token) { 148 TokenType getTokenType(Token token) {
151 switch (token.kind) { 149 switch (token.kind) {
152 case EOF_TOKEN: return TokenType.EOF; 150 case EOF_TOKEN: return TokenType.EOF;
153 case DOUBLE_TOKEN: return TokenType.DOUBLE; 151 case DOUBLE_TOKEN: return TokenType.DOUBLE;
154 case HEXADECIMAL_TOKEN: return TokenType.HEXADECIMAL; 152 case HEXADECIMAL_TOKEN: return TokenType.HEXADECIMAL;
155 case IDENTIFIER_TOKEN: return TokenType.IDENTIFIER; 153 case IDENTIFIER_TOKEN: return TokenType.IDENTIFIER;
156 case INT_TOKEN: return TokenType.INT; 154 case INT_TOKEN: return TokenType.INT;
157 case KEYWORD_TOKEN: return TokenType.KEYWORD; 155 case KEYWORD_TOKEN: return TokenType.KEYWORD;
158 // case MULTI_LINE_COMMENT_TOKEN: return TokenType.MULTI_LINE_COMMENT; 156 // case MULTI_LINE_COMMENT_TOKEN: return TokenType.MULTI_LINE_COMMENT;
159 // case SCRIPT_TAG_TOKEN: return TokenType.SCRIPT_TAG; 157 // case SCRIPT_TAG_TOKEN: return TokenType.SCRIPT_TAG;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 case BACKSLASH_TOKEN: return TokenType.BACKSLASH; 224 case BACKSLASH_TOKEN: return TokenType.BACKSLASH;
227 case PERIOD_PERIOD_PERIOD_TOKEN: return TokenType.PERIOD_PERIOD_PERIOD; 225 case PERIOD_PERIOD_PERIOD_TOKEN: return TokenType.PERIOD_PERIOD_PERIOD;
228 // case GENERIC_METHOD_TYPE_LIST_TOKEN: 226 // case GENERIC_METHOD_TYPE_LIST_TOKEN:
229 // return TokenType.GENERIC_METHOD_TYPE_LIST; 227 // return TokenType.GENERIC_METHOD_TYPE_LIST;
230 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN: 228 // case GENERIC_METHOD_TYPE_ASSIGN_TOKEN:
231 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN; 229 // return TokenType.GENERIC_METHOD_TYPE_ASSIGN;
232 default: 230 default:
233 return internalError("Unhandled token ${token.info}"); 231 return internalError("Unhandled token ${token.info}");
234 } 232 }
235 } 233 }
OLDNEW
« 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