OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * A mini parser that extracts top-level directives (library, imports, exports, | 6 * A mini parser that extracts top-level directives (library, imports, exports, |
7 * and parts) from a dart source file. | 7 * and parts) from a dart source file. |
8 */ | 8 */ |
9 library directive_parser; | 9 library directive_parser; |
10 | 10 |
11 import 'info.dart' show DartCodeInfo, DartDirectiveInfo; | 11 import 'info.dart' show DartCodeInfo, DartDirectiveInfo; |
12 import 'messages.dart' show Messages; | 12 import 'messages.dart' show Messages; |
13 import 'file_system/path.dart'; | 13 import 'file_system/path.dart'; |
14 | 14 |
15 /** | 15 /** |
16 * Parse and extract top-level directives from [code]. | 16 * Parse and extract top-level directives from [code]. |
17 * | 17 * |
18 * Adds emitted error/warning messages to [messages], if [messages] is | 18 * Adds emitted error/warning messages to [messages], if [messages] is |
19 * supplied. | 19 * supplied. |
20 */ | 20 */ |
21 DartCodeInfo parseDartCode(String code, Path file, {Messages messages}) { | 21 DartCodeInfo parseDartCode(String code, Path file, {Messages messages}) { |
22 messages = messages == null ? new Messages.silent() : messages; | 22 messages = messages == null ? new Messages.silent() : messages; |
23 return new _DirectiveParser(messages, file).parse(code); | 23 return new _DirectiveParser(messages, file).parse(code); |
24 } | 24 } |
25 | 25 |
26 /** A parser that extracts top-level directives. */ | 26 /** A parser that extracts top-level directives. */ |
27 // TODO(sigmund): add source-span to error messages | 27 // TODO(sigmund): add source-span to error messages. |
| 28 // TODO(jmesserly): replace this with something based on compiler_unsupported. |
28 class _DirectiveParser { | 29 class _DirectiveParser { |
29 /** Path to the source file containing the code (for error messages). */ | 30 /** Path to the source file containing the code (for error messages). */ |
30 Path file; | 31 Path file; |
31 | 32 |
32 /** Tokenizer used to parse the input until the end of the directives. */ | 33 /** Tokenizer used to parse the input until the end of the directives. */ |
33 _DirectiveTokenizer tokenizer; | 34 _DirectiveTokenizer tokenizer; |
34 | 35 |
35 /** Extracted library identifier, if any. */ | 36 /** Extracted library identifier, if any. */ |
36 String libraryName; | 37 String libraryName; |
37 | 38 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 static const int _ZERO = 48; // 0 | 380 static const int _ZERO = 48; // 0 |
380 static const int _NINE = 57; // 9 | 381 static const int _NINE = 57; // 9 |
381 static const int _SEMICOLON = 59; // ; | 382 static const int _SEMICOLON = 59; // ; |
382 static const int _UPPER_A = 65; // A | 383 static const int _UPPER_A = 65; // A |
383 static const int _UPPER_Z = 90; // Z | 384 static const int _UPPER_Z = 90; // Z |
384 static const int _BACKSLASH = 92; // \ | 385 static const int _BACKSLASH = 92; // \ |
385 static const int _UNDERSCORE = 95; // _ | 386 static const int _UNDERSCORE = 95; // _ |
386 static const int _LOWER_A = 97; // a | 387 static const int _LOWER_A = 97; // a |
387 static const int _LOWER_Z = 122; // z | 388 static const int _LOWER_Z = 122; // z |
388 } | 389 } |
OLD | NEW |