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

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

Issue 2842213003: new TokenType and Keyword API (Closed)
Patch Set: rebase Created 3 years, 7 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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.scanner.keywords; 5 library fasta.scanner.keywords;
6 6
7 import '../../scanner/token.dart' as analyzer; 7 import '../../scanner/token.dart' as analyzer;
8 8
9 import 'characters.dart' show $a, $z, $A, $Z; 9 import 'characters.dart' show $a, $z, $A, $Z;
10 10
11 /** 11 /**
12 * Abstract state in a state machine for scanning keywords. 12 * Abstract state in a state machine for scanning keywords.
13 */ 13 */
14 abstract class KeywordState { 14 abstract class KeywordState {
15 KeywordState next(int c); 15 KeywordState next(int c);
16 KeywordState nextCapital(int c); 16 KeywordState nextCapital(int c);
17 17
18 analyzer.Keyword get keyword; 18 analyzer.Keyword get keyword;
19 19
20 static KeywordState _KEYWORD_STATE; 20 static KeywordState _KEYWORD_STATE;
21 static KeywordState get KEYWORD_STATE { 21 static KeywordState get KEYWORD_STATE {
22 if (_KEYWORD_STATE == null) { 22 if (_KEYWORD_STATE == null) {
23 List<String> strings = new List<String>(analyzer.Keyword.values.length); 23 List<String> strings = new List<String>(analyzer.Keyword.values.length);
24 for (int i = 0; i < analyzer.Keyword.values.length; i++) { 24 for (int i = 0; i < analyzer.Keyword.values.length; i++) {
25 strings[i] = analyzer.Keyword.values[i].syntax; 25 strings[i] = analyzer.Keyword.values[i].lexeme;
26 } 26 }
27 strings.sort((a, b) => a.compareTo(b)); 27 strings.sort((a, b) => a.compareTo(b));
28 _KEYWORD_STATE = computeKeywordStateTable(0, strings, 0, strings.length); 28 _KEYWORD_STATE = computeKeywordStateTable(0, strings, 0, strings.length);
29 } 29 }
30 return _KEYWORD_STATE; 30 return _KEYWORD_STATE;
31 } 31 }
32 32
33 static KeywordState computeKeywordStateTable( 33 static KeywordState computeKeywordStateTable(
34 int start, List<String> strings, int offset, int length) { 34 int start, List<String> strings, int offset, int length) {
35 bool isLowercase = true; 35 bool isLowercase = true;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 * A state that has no outgoing transitions. 137 * A state that has no outgoing transitions.
138 */ 138 */
139 class LeafKeywordState implements KeywordState { 139 class LeafKeywordState implements KeywordState {
140 final analyzer.Keyword keyword; 140 final analyzer.Keyword keyword;
141 141
142 LeafKeywordState(String syntax) : keyword = analyzer.Keyword.keywords[syntax]; 142 LeafKeywordState(String syntax) : keyword = analyzer.Keyword.keywords[syntax];
143 143
144 KeywordState next(int c) => null; 144 KeywordState next(int c) => null;
145 KeywordState nextCapital(int c) => null; 145 KeywordState nextCapital(int c) => null;
146 146
147 String toString() => keyword.syntax; 147 String toString() => keyword.lexeme;
148 } 148 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/array_based_scanner.dart ('k') | pkg/front_end/lib/src/fasta/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698