OLD | NEW |
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 import 'precedence.dart' show PrecedenceInfo; | 11 import 'precedence.dart' show PrecedenceInfo; |
12 | 12 |
13 import 'precedence.dart' show AS_INFO, IS_INFO, KEYWORD_INFO; | 13 import 'precedence.dart' show AS_INFO, IS_INFO, KEYWORD_INFO; |
14 | 14 |
15 /** | 15 /** |
16 * A keyword in the Dart programming language. | 16 * A keyword in the Dart programming language. |
17 */ | 17 */ |
18 class Keyword implements analyzer.Keyword { | 18 class Keyword extends analyzer.Keyword { |
19 static const ASSERT = const Keyword("assert"); | 19 static const ASSERT = const Keyword("assert"); |
20 static const BREAK = const Keyword("break"); | 20 static const BREAK = const Keyword("break"); |
21 static const CASE = const Keyword("case"); | 21 static const CASE = const Keyword("case"); |
22 static const CATCH = const Keyword("catch"); | 22 static const CATCH = const Keyword("catch"); |
23 static const CLASS = const Keyword("class"); | 23 static const CLASS = const Keyword("class"); |
24 static const CONST = const Keyword("const"); | 24 static const CONST = const Keyword("const"); |
25 static const CONTINUE = const Keyword("continue"); | 25 static const CONTINUE = const Keyword("continue"); |
26 static const DEFAULT = const Keyword("default"); | 26 static const DEFAULT = const Keyword("default"); |
27 static const DO = const Keyword("do"); | 27 static const DO = const Keyword("do"); |
28 static const ELSE = const Keyword("else"); | 28 static const ELSE = const Keyword("else"); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 NATIVE, | 145 NATIVE, |
146 OF, | 146 OF, |
147 ON, | 147 ON, |
148 PATCH, | 148 PATCH, |
149 SHOW, | 149 SHOW, |
150 SOURCE, | 150 SOURCE, |
151 SYNC, | 151 SYNC, |
152 YIELD, | 152 YIELD, |
153 ]; | 153 ]; |
154 | 154 |
155 final String syntax; | |
156 final bool isPseudo; | |
157 final bool isBuiltIn; | |
158 final PrecedenceInfo info; | |
159 | |
160 static Map<String, Keyword> _keywords; | 155 static Map<String, Keyword> _keywords; |
161 static Map<String, Keyword> get keywords { | 156 static Map<String, Keyword> get keywords { |
162 if (_keywords == null) { | 157 if (_keywords == null) { |
163 _keywords = computeKeywordMap(); | 158 _keywords = computeKeywordMap(); |
164 } | 159 } |
165 return _keywords; | 160 return _keywords; |
166 } | 161 } |
167 | 162 |
168 const Keyword(this.syntax, | 163 const Keyword(String syntax, |
169 {this.isPseudo: false, this.isBuiltIn: false, this.info: KEYWORD_INFO}); | 164 {bool isPseudo: false, |
| 165 bool isBuiltIn: false, |
| 166 PrecedenceInfo info: KEYWORD_INFO}) |
| 167 : super(syntax, info: info, isBuiltIn: isBuiltIn, isPseudo: isPseudo); |
170 | 168 |
171 static Map<String, Keyword> computeKeywordMap() { | 169 static Map<String, Keyword> computeKeywordMap() { |
172 Map<String, Keyword> result = new Map<String, Keyword>(); | 170 Map<String, Keyword> result = new Map<String, Keyword>(); |
173 for (Keyword keyword in values) { | 171 for (Keyword keyword in values) { |
174 result[keyword.syntax] = keyword; | 172 result[keyword.syntax] = keyword; |
175 } | 173 } |
176 return result; | 174 return result; |
177 } | 175 } |
178 | |
179 String toString() => syntax; | |
180 | |
181 /// The term "pseudo-keyword" doesn't exist in the spec, and | |
182 /// Analyzer and Fasta have different notions of what it means. | |
183 /// Analyzer's notion of "pseudo-keyword" corresponds with Fasta's | |
184 /// notion of "built-in keyword". | |
185 /// Use [isBuiltIn] instead. | |
186 @override | |
187 bool get isPseudoKeyword => isBuiltIn; | |
188 | |
189 @override | |
190 String get name => syntax.toUpperCase(); | |
191 } | 176 } |
192 | 177 |
193 /** | 178 /** |
194 * Abstract state in a state machine for scanning keywords. | 179 * Abstract state in a state machine for scanning keywords. |
195 */ | 180 */ |
196 abstract class KeywordState { | 181 abstract class KeywordState { |
197 KeywordState next(int c); | 182 KeywordState next(int c); |
198 KeywordState nextCapital(int c); | 183 KeywordState nextCapital(int c); |
199 | 184 |
200 Keyword get keyword; | 185 Keyword get keyword; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 class LeafKeywordState implements KeywordState { | 306 class LeafKeywordState implements KeywordState { |
322 final Keyword keyword; | 307 final Keyword keyword; |
323 | 308 |
324 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax]; | 309 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax]; |
325 | 310 |
326 KeywordState next(int c) => null; | 311 KeywordState next(int c) => null; |
327 KeywordState nextCapital(int c) => null; | 312 KeywordState nextCapital(int c) => null; |
328 | 313 |
329 String toString() => keyword.syntax; | 314 String toString() => keyword.syntax; |
330 } | 315 } |
OLD | NEW |