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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library dart_scanner; | 5 library dart_scanner; |
6 | 6 |
7 import 'src/token.dart' show | 7 import 'src/token.dart' show |
8 Token; | 8 Token; |
9 | 9 |
10 import 'src/utf8_bytes_scanner.dart' show | 10 import 'src/utf8_bytes_scanner.dart' show |
11 Utf8BytesScanner; | 11 Utf8BytesScanner; |
12 | 12 |
| 13 export 'src/token.dart' show |
| 14 BeginGroupToken, |
| 15 ErrorToken, |
| 16 KeywordToken, |
| 17 StringToken, |
| 18 SymbolToken, |
| 19 Token, |
| 20 isBinaryOperator, |
| 21 isMinusOperator, |
| 22 isTernaryOperator, |
| 23 isUnaryOperator, |
| 24 isUserDefinableOperator; |
| 25 |
| 26 export 'src/token_constants.dart' show |
| 27 EOF_TOKEN; |
| 28 |
| 29 export 'src/utf8_bytes_scanner.dart' show |
| 30 Utf8BytesScanner; |
| 31 |
| 32 export 'src/string_scanner.dart' show |
| 33 StringScanner; |
| 34 |
| 35 export 'src/keyword.dart' show |
| 36 Keyword; |
| 37 |
13 abstract class Scanner { | 38 abstract class Scanner { |
14 List<int> get lineStarts; | 39 List<int> get lineStarts; |
15 Token tokenize(); | 40 Token tokenize(); |
16 } | 41 } |
17 | 42 |
18 class ScannerResult { | 43 class ScannerResult { |
19 final Token tokens; | 44 final Token tokens; |
20 final List<int> lineStarts; | 45 final List<int> lineStarts; |
21 | 46 |
22 ScannerResult(this.tokens, this.lineStarts); | 47 ScannerResult(this.tokens, this.lineStarts); |
23 } | 48 } |
24 | 49 |
25 ScannerResult scan(List<int> bytes, {bool includeComments: false}) { | 50 ScannerResult scan(List<int> bytes, {bool includeComments: false}) { |
26 if (bytes.last != 0) { | 51 if (bytes.last != 0) { |
27 throw new ArgumentError("[bytes]: the last byte must be null."); | 52 throw new ArgumentError("[bytes]: the last byte must be null."); |
28 } | 53 } |
29 Scanner scanner = | 54 Scanner scanner = |
30 new Utf8BytesScanner(bytes, includeComments: includeComments); | 55 new Utf8BytesScanner(bytes, includeComments: includeComments); |
31 return new ScannerResult(scanner.tokenize(), scanner.lineStarts); | 56 return new ScannerResult(scanner.tokenize(), scanner.lineStarts); |
32 } | 57 } |
OLD | NEW |