OLD | NEW |
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 /** | 5 /** |
6 * Defines the tokens that are produced by the scanner, used by the parser, and | 6 * Defines the tokens that are produced by the scanner, used by the parser, and |
7 * referenced from the [AST structure](ast.dart). | 7 * referenced from the [AST structure](ast.dart). |
8 */ | 8 */ |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 | 10 |
11 import 'package:front_end/src/base/syntactic_entity.dart'; | 11 import 'package:front_end/src/base/syntactic_entity.dart'; |
12 import 'package:front_end/src/scanner/string_utilities.dart'; | 12 import 'package:front_end/src/scanner/string_utilities.dart'; |
| 13 import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; |
13 | 14 |
14 /** | 15 /** |
15 * The opening half of a grouping pair of tokens. This is used for curly | 16 * The opening half of a grouping pair of tokens. This is used for curly |
16 * brackets ('{'), parentheses ('('), and square brackets ('['). | 17 * brackets ('{'), parentheses ('('), and square brackets ('['). |
17 */ | 18 */ |
18 class BeginToken extends SimpleToken { | 19 class BeginToken extends SimpleToken { |
19 /** | 20 /** |
20 * The token that corresponds to this token. | 21 * The token that corresponds to this token. |
21 */ | 22 */ |
22 Token endToken; | 23 Token endToken; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 references.forEach((ref) => copy.references.add(ref.copy())); | 141 references.forEach((ref) => copy.references.add(ref.copy())); |
141 return copy; | 142 return copy; |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 /** | 146 /** |
146 * The keywords in the Dart programming language. | 147 * The keywords in the Dart programming language. |
147 * | 148 * |
148 * Clients may not extend, implement or mix-in this class. | 149 * Clients may not extend, implement or mix-in this class. |
149 */ | 150 */ |
150 class Keyword { | 151 abstract class Keyword { |
151 static const Keyword ABSTRACT = const Keyword._('ABSTRACT', "abstract", true); | 152 static const Keyword ABSTRACT = fasta.Keyword.ABSTRACT; |
152 | 153 |
153 static const Keyword AS = const Keyword._('AS', "as", true); | 154 static const Keyword AS = fasta.Keyword.AS; |
154 | 155 |
155 static const Keyword ASSERT = const Keyword._('ASSERT', "assert"); | 156 static const Keyword ASSERT = fasta.Keyword.ASSERT; |
156 | 157 |
157 static const Keyword BREAK = const Keyword._('BREAK', "break"); | 158 static const Keyword BREAK = fasta.Keyword.BREAK; |
158 | 159 |
159 static const Keyword CASE = const Keyword._('CASE', "case"); | 160 static const Keyword CASE = fasta.Keyword.CASE; |
160 | 161 |
161 static const Keyword CATCH = const Keyword._('CATCH', "catch"); | 162 static const Keyword CATCH = fasta.Keyword.CATCH; |
162 | 163 |
163 static const Keyword CLASS = const Keyword._('CLASS', "class"); | 164 static const Keyword CLASS = fasta.Keyword.CLASS; |
164 | 165 |
165 static const Keyword CONST = const Keyword._('CONST', "const"); | 166 static const Keyword CONST = fasta.Keyword.CONST; |
166 | 167 |
167 static const Keyword CONTINUE = const Keyword._('CONTINUE', "continue"); | 168 static const Keyword CONTINUE = fasta.Keyword.CONTINUE; |
168 | 169 |
169 static const Keyword COVARIANT = | 170 static const Keyword COVARIANT = fasta.Keyword.COVARIANT; |
170 const Keyword._('COVARIANT', "covariant", true); | |
171 | 171 |
172 static const Keyword DEFAULT = const Keyword._('DEFAULT', "default"); | 172 static const Keyword DEFAULT = fasta.Keyword.DEFAULT; |
173 | 173 |
174 static const Keyword DEFERRED = const Keyword._('DEFERRED', "deferred", true); | 174 static const Keyword DEFERRED = fasta.Keyword.DEFERRED; |
175 | 175 |
176 static const Keyword DO = const Keyword._('DO', "do"); | 176 static const Keyword DO = fasta.Keyword.DO; |
177 | 177 |
178 static const Keyword DYNAMIC = const Keyword._('DYNAMIC', "dynamic", true); | 178 static const Keyword DYNAMIC = fasta.Keyword.DYNAMIC; |
179 | 179 |
180 static const Keyword ELSE = const Keyword._('ELSE', "else"); | 180 static const Keyword ELSE = fasta.Keyword.ELSE; |
181 | 181 |
182 static const Keyword ENUM = const Keyword._('ENUM', "enum"); | 182 static const Keyword ENUM = fasta.Keyword.ENUM; |
183 | 183 |
184 static const Keyword EXPORT = const Keyword._('EXPORT', "export", true); | 184 static const Keyword EXPORT = fasta.Keyword.EXPORT; |
185 | 185 |
186 static const Keyword EXTENDS = const Keyword._('EXTENDS', "extends"); | 186 static const Keyword EXTENDS = fasta.Keyword.EXTENDS; |
187 | 187 |
188 static const Keyword EXTERNAL = const Keyword._('EXTERNAL', "external", true); | 188 static const Keyword EXTERNAL = fasta.Keyword.EXTERNAL; |
189 | 189 |
190 static const Keyword FACTORY = const Keyword._('FACTORY', "factory", true); | 190 static const Keyword FACTORY = fasta.Keyword.FACTORY; |
191 | 191 |
192 static const Keyword FALSE = const Keyword._('FALSE', "false"); | 192 static const Keyword FALSE = fasta.Keyword.FALSE; |
193 | 193 |
194 static const Keyword FINAL = const Keyword._('FINAL', "final"); | 194 static const Keyword FINAL = fasta.Keyword.FINAL; |
195 | 195 |
196 static const Keyword FINALLY = const Keyword._('FINALLY', "finally"); | 196 static const Keyword FINALLY = fasta.Keyword.FINALLY; |
197 | 197 |
198 static const Keyword FOR = const Keyword._('FOR', "for"); | 198 static const Keyword FOR = fasta.Keyword.FOR; |
199 | 199 |
200 static const Keyword GET = const Keyword._('GET', "get", true); | 200 static const Keyword GET = fasta.Keyword.GET; |
201 | 201 |
202 static const Keyword IF = const Keyword._('IF', "if"); | 202 static const Keyword IF = fasta.Keyword.IF; |
203 | 203 |
204 static const Keyword IMPLEMENTS = | 204 static const Keyword IMPLEMENTS = fasta.Keyword.IMPLEMENTS; |
205 const Keyword._('IMPLEMENTS', "implements", true); | |
206 | 205 |
207 static const Keyword IMPORT = const Keyword._('IMPORT', "import", true); | 206 static const Keyword IMPORT = fasta.Keyword.IMPORT; |
208 | 207 |
209 static const Keyword IN = const Keyword._('IN', "in"); | 208 static const Keyword IN = fasta.Keyword.IN; |
210 | 209 |
211 static const Keyword IS = const Keyword._('IS', "is"); | 210 static const Keyword IS = fasta.Keyword.IS; |
212 | 211 |
213 static const Keyword LIBRARY = const Keyword._('LIBRARY', "library", true); | 212 static const Keyword LIBRARY = fasta.Keyword.LIBRARY; |
214 | 213 |
215 static const Keyword NEW = const Keyword._('NEW', "new"); | 214 static const Keyword NEW = fasta.Keyword.NEW; |
216 | 215 |
217 static const Keyword NULL = const Keyword._('NULL', "null"); | 216 static const Keyword NULL = fasta.Keyword.NULL; |
218 | 217 |
219 static const Keyword OPERATOR = const Keyword._('OPERATOR', "operator", true); | 218 static const Keyword OPERATOR = fasta.Keyword.OPERATOR; |
220 | 219 |
221 static const Keyword PART = const Keyword._('PART', "part", true); | 220 static const Keyword PART = fasta.Keyword.PART; |
222 | 221 |
223 static const Keyword RETHROW = const Keyword._('RETHROW', "rethrow"); | 222 static const Keyword RETHROW = fasta.Keyword.RETHROW; |
224 | 223 |
225 static const Keyword RETURN = const Keyword._('RETURN', "return"); | 224 static const Keyword RETURN = fasta.Keyword.RETURN; |
226 | 225 |
227 static const Keyword SET = const Keyword._('SET', "set", true); | 226 static const Keyword SET = fasta.Keyword.SET; |
228 | 227 |
229 static const Keyword STATIC = const Keyword._('STATIC', "static", true); | 228 static const Keyword STATIC = fasta.Keyword.STATIC; |
230 | 229 |
231 static const Keyword SUPER = const Keyword._('SUPER', "super"); | 230 static const Keyword SUPER = fasta.Keyword.SUPER; |
232 | 231 |
233 static const Keyword SWITCH = const Keyword._('SWITCH', "switch"); | 232 static const Keyword SWITCH = fasta.Keyword.SWITCH; |
234 | 233 |
235 static const Keyword THIS = const Keyword._('THIS', "this"); | 234 static const Keyword THIS = fasta.Keyword.THIS; |
236 | 235 |
237 static const Keyword THROW = const Keyword._('THROW', "throw"); | 236 static const Keyword THROW = fasta.Keyword.THROW; |
238 | 237 |
239 static const Keyword TRUE = const Keyword._('TRUE', "true"); | 238 static const Keyword TRUE = fasta.Keyword.TRUE; |
240 | 239 |
241 static const Keyword TRY = const Keyword._('TRY', "try"); | 240 static const Keyword TRY = fasta.Keyword.TRY; |
242 | 241 |
243 static const Keyword TYPEDEF = const Keyword._('TYPEDEF', "typedef", true); | 242 static const Keyword TYPEDEF = fasta.Keyword.TYPEDEF; |
244 | 243 |
245 static const Keyword VAR = const Keyword._('VAR', "var"); | 244 static const Keyword VAR = fasta.Keyword.VAR; |
246 | 245 |
247 static const Keyword VOID = const Keyword._('VOID', "void"); | 246 static const Keyword VOID = fasta.Keyword.VOID; |
248 | 247 |
249 static const Keyword WHILE = const Keyword._('WHILE', "while"); | 248 static const Keyword WHILE = fasta.Keyword.WHILE; |
250 | 249 |
251 static const Keyword WITH = const Keyword._('WITH', "with"); | 250 static const Keyword WITH = fasta.Keyword.WITH; |
252 | 251 |
253 static const List<Keyword> values = const <Keyword>[ | 252 static const List<Keyword> values = const <Keyword>[ |
254 ABSTRACT, | 253 ABSTRACT, |
255 AS, | 254 AS, |
256 ASSERT, | 255 ASSERT, |
257 BREAK, | 256 BREAK, |
258 CASE, | 257 CASE, |
259 CATCH, | 258 CATCH, |
260 CLASS, | 259 CLASS, |
261 CONST, | 260 CONST, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 ]; | 303 ]; |
305 | 304 |
306 /** | 305 /** |
307 * A table mapping the lexemes of keywords to the corresponding keyword. | 306 * A table mapping the lexemes of keywords to the corresponding keyword. |
308 */ | 307 */ |
309 static final Map<String, Keyword> keywords = _createKeywordMap(); | 308 static final Map<String, Keyword> keywords = _createKeywordMap(); |
310 | 309 |
311 /** | 310 /** |
312 * The name of the keyword type. | 311 * The name of the keyword type. |
313 */ | 312 */ |
314 final String name; | 313 String get name; |
315 | 314 |
316 /** | 315 /** |
317 * The lexeme for the keyword. | 316 * The lexeme for the keyword. |
318 */ | 317 */ |
319 final String syntax; | 318 String get syntax; |
320 | 319 |
321 /** | 320 /** |
322 * A flag indicating whether the keyword is a pseudo-keyword. Pseudo keywords | 321 * A flag indicating whether the keyword is a pseudo-keyword. Pseudo keywords |
323 * can be used as identifiers. | 322 * can be used as identifiers. |
324 */ | 323 */ |
325 final bool isPseudoKeyword; | 324 bool get isPseudoKeyword; |
326 | |
327 /** | |
328 * Initialize a newly created keyword to have the given [name] and [syntax]. | |
329 * The keyword is a pseudo-keyword if the [isPseudoKeyword] flag is `true`. | |
330 */ | |
331 const Keyword._(this.name, this.syntax, [this.isPseudoKeyword = false]); | |
332 | |
333 @override | |
334 String toString() => name; | |
335 | 325 |
336 /** | 326 /** |
337 * Create a table mapping the lexemes of keywords to the corresponding keyword | 327 * Create a table mapping the lexemes of keywords to the corresponding keyword |
338 * and return the table that was created. | 328 * and return the table that was created. |
339 */ | 329 */ |
340 static Map<String, Keyword> _createKeywordMap() { | 330 static Map<String, Keyword> _createKeywordMap() { |
341 LinkedHashMap<String, Keyword> result = | 331 LinkedHashMap<String, Keyword> result = |
342 new LinkedHashMap<String, Keyword>(); | 332 new LinkedHashMap<String, Keyword>(); |
343 for (Keyword keyword in values) { | 333 for (Keyword keyword in values) { |
344 result[keyword.syntax] = keyword; | 334 result[keyword.syntax] = keyword; |
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 */ | 1275 */ |
1286 class _EndOfFileTokenType extends TokenType { | 1276 class _EndOfFileTokenType extends TokenType { |
1287 /** | 1277 /** |
1288 * Initialize a newly created token. | 1278 * Initialize a newly created token. |
1289 */ | 1279 */ |
1290 const _EndOfFileTokenType() : super._('EOF', TokenClass.NO_CLASS, ''); | 1280 const _EndOfFileTokenType() : super._('EOF', TokenClass.NO_CLASS, ''); |
1291 | 1281 |
1292 @override | 1282 @override |
1293 String toString() => '-eof-'; | 1283 String toString() => '-eof-'; |
1294 } | 1284 } |
OLD | NEW |