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

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

Issue 2842643004: flatten Keyword into TokenType (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/scanner/token.dart' show Keyword; 9 import 'package:front_end/src/scanner/token.dart' show Keyword;
10 10
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 analyzerToken = translateAndAppend(analyzerToken); 272 analyzerToken = translateAndAppend(analyzerToken);
273 } 273 }
274 } 274 }
275 275
276 /// Converts a single analyzer token into a Fasta token. 276 /// Converts a single analyzer token into a Fasta token.
277 Token fromAnalyzerToken(analyzer.Token token) { 277 Token fromAnalyzerToken(analyzer.Token token) {
278 Token beginGroup(TokenType info) => new BeginGroupToken(info, token.offset); 278 Token beginGroup(TokenType info) => new BeginGroupToken(info, token.offset);
279 Token string(TokenType info) => 279 Token string(TokenType info) =>
280 new StringToken.fromString(info, token.lexeme, token.offset); 280 new StringToken.fromString(info, token.lexeme, token.offset);
281 Token symbol(TokenType info) => new SymbolToken(info, token.offset); 281 Token symbol(TokenType info) => new SymbolToken(info, token.offset);
282 if (token.type.isKeyword) {
283 var keyword = Keyword.keywords[token.lexeme];
284 if (keyword != null) {
285 return new KeywordToken(keyword, token.offset);
286 } else {
287 return internalError("Unrecognized keyword: '${token.lexeme}'.");
288 }
289 }
282 switch (token.type) { 290 switch (token.type) {
283 case TokenType.DOUBLE: 291 case TokenType.DOUBLE:
284 return string(TokenType.DOUBLE); 292 return string(TokenType.DOUBLE);
285 case TokenType.HEXADECIMAL: 293 case TokenType.HEXADECIMAL:
286 return string(TokenType.HEXADECIMAL); 294 return string(TokenType.HEXADECIMAL);
287 case TokenType.IDENTIFIER: 295 case TokenType.IDENTIFIER:
288 // Certain identifiers have special grammatical meanings even though they 296 // Certain identifiers have special grammatical meanings even though they
289 // are neither keywords nor built-in identifiers (e.g. "async"). Analyzer 297 // are neither keywords nor built-in identifiers (e.g. "async"). Analyzer
290 // represents these as identifiers. Fasta represents them as keywords 298 // represents these as identifiers. Fasta represents them as keywords
291 // with the "isPseudo" property. 299 // with the "isPseudo" property.
292 var keyword = Keyword.keywords[token.lexeme]; 300 var keyword = Keyword.keywords[token.lexeme];
293 if (keyword != null) { 301 if (keyword != null) {
294 assert(keyword.isPseudo); 302 assert(keyword.isPseudo);
295 return new KeywordToken(keyword, token.offset); 303 return new KeywordToken(keyword, token.offset);
296 } else { 304 } else {
297 return string(TokenType.IDENTIFIER); 305 return string(TokenType.IDENTIFIER);
298 } 306 }
299 break; 307 break;
300 case TokenType.INT: 308 case TokenType.INT:
301 return string(TokenType.INT); 309 return string(TokenType.INT);
302 case TokenType.KEYWORD:
303 var keyword = Keyword.keywords[token.lexeme];
304 if (keyword != null) {
305 return new KeywordToken(keyword, token.offset);
306 } else {
307 return internalError("Unrecognized keyword: '${token.lexeme}'.");
308 }
309 break;
310 case TokenType.MULTI_LINE_COMMENT: 310 case TokenType.MULTI_LINE_COMMENT:
311 if (token.lexeme.startsWith('/**')) { 311 if (token.lexeme.startsWith('/**')) {
312 return new DartDocToken.fromSubstring(TokenType.MULTI_LINE_COMMENT, 312 return new DartDocToken.fromSubstring(TokenType.MULTI_LINE_COMMENT,
313 token.lexeme, 0, token.lexeme.length, 0); 313 token.lexeme, 0, token.lexeme.length, 0);
314 } 314 }
315 return new CommentToken.fromSubstring(TokenType.MULTI_LINE_COMMENT, 315 return new CommentToken.fromSubstring(TokenType.MULTI_LINE_COMMENT,
316 token.lexeme, 0, token.lexeme.length, 0); 316 token.lexeme, 0, token.lexeme.length, 0);
317 case TokenType.SCRIPT_TAG: 317 case TokenType.SCRIPT_TAG:
318 return string(TokenType.SCRIPT_TAG); 318 return string(TokenType.SCRIPT_TAG);
319 case TokenType.SINGLE_LINE_COMMENT: 319 case TokenType.SINGLE_LINE_COMMENT:
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 return makeStringToken(TokenType.HEXADECIMAL); 484 return makeStringToken(TokenType.HEXADECIMAL);
485 485
486 case IDENTIFIER_TOKEN: 486 case IDENTIFIER_TOKEN:
487 return makeStringToken(TokenType.IDENTIFIER); 487 return makeStringToken(TokenType.IDENTIFIER);
488 488
489 case INT_TOKEN: 489 case INT_TOKEN:
490 return makeStringToken(TokenType.INT); 490 return makeStringToken(TokenType.INT);
491 491
492 case KEYWORD_TOKEN: 492 case KEYWORD_TOKEN:
493 KeywordToken keywordToken = token; 493 KeywordToken keywordToken = token;
494 var syntax = keywordToken.keyword.syntax; 494 var syntax = keywordToken.keyword.lexeme;
495 // TODO(paulberry): if the map lookup proves to be too slow, consider 495 // TODO(paulberry): if the map lookup proves to be too slow, consider
496 // using a switch statement, or perhaps a string of 496 // using a switch statement, or perhaps a string of
497 // "if (identical(syntax, "foo"))" checks. (Note that identical checks 497 // "if (identical(syntax, "foo"))" checks. (Note that identical checks
498 // should be safe because the Fasta scanner uses string literals for 498 // should be safe because the Fasta scanner uses string literals for
499 // the values of keyword.syntax.) 499 // the values of keyword.syntax.)
500 var keyword = 500 var keyword =
501 _keywordMap[syntax] ?? internalError('Unknown keyword: $syntax'); 501 _keywordMap[syntax] ?? internalError('Unknown keyword: $syntax');
502 if (commentToken == null) { 502 if (commentToken == null) {
503 return new analyzer.KeywordToken(keyword, token.charOffset); 503 return new analyzer.KeywordToken(keyword, token.charOffset);
504 } else { 504 } else {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 "hide": analyzer.Keyword.HIDE, 590 "hide": analyzer.Keyword.HIDE,
591 "native": analyzer.Keyword.NATIVE, 591 "native": analyzer.Keyword.NATIVE,
592 "of": analyzer.Keyword.OF, 592 "of": analyzer.Keyword.OF,
593 "on": analyzer.Keyword.ON, 593 "on": analyzer.Keyword.ON,
594 "patch": analyzer.Keyword.PATCH, 594 "patch": analyzer.Keyword.PATCH,
595 "show": analyzer.Keyword.SHOW, 595 "show": analyzer.Keyword.SHOW,
596 "source": analyzer.Keyword.SOURCE, 596 "source": analyzer.Keyword.SOURCE,
597 "sync": analyzer.Keyword.SYNC, 597 "sync": analyzer.Keyword.SYNC,
598 "yield": analyzer.Keyword.YIELD, 598 "yield": analyzer.Keyword.YIELD,
599 }; 599 };
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/type.dart ('k') | pkg/analyzer/lib/src/generated/error_verifier.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698