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 fasta.scanner; | 5 library fasta.scanner; |
6 | 6 |
7 import 'dart:convert' show UNICODE_REPLACEMENT_CHARACTER_RUNE, UTF8; | 7 import 'dart:convert' show UNICODE_REPLACEMENT_CHARACTER_RUNE, UTF8; |
8 | 8 |
9 import 'scanner/token.dart' show Token; | 9 import '../scanner/token.dart' show Token; |
10 | 10 |
11 import 'scanner/string_scanner.dart' show StringScanner; | 11 import 'scanner/string_scanner.dart' show StringScanner; |
12 | 12 |
13 import 'scanner/utf8_bytes_scanner.dart' show Utf8BytesScanner; | 13 import 'scanner/utf8_bytes_scanner.dart' show Utf8BytesScanner; |
14 | 14 |
15 import 'scanner/recover.dart' show defaultRecoveryStrategy; | 15 import 'scanner/recover.dart' show defaultRecoveryStrategy; |
16 | 16 |
17 export 'scanner/token.dart' | 17 export 'scanner/token.dart' |
18 show | 18 show |
19 BeginGroupToken, | 19 BeginGroupToken, |
20 KeywordToken, | |
21 StringToken, | 20 StringToken, |
22 SymbolToken, | 21 SymbolToken, |
23 Token, | |
24 isBinaryOperator, | 22 isBinaryOperator, |
25 isMinusOperator, | 23 isMinusOperator, |
26 isTernaryOperator, | 24 isTernaryOperator, |
27 isUnaryOperator, | 25 isUnaryOperator, |
28 isUserDefinableOperator; | 26 isUserDefinableOperator; |
29 | 27 |
30 export 'scanner/error_token.dart' | 28 export 'scanner/error_token.dart' |
31 show ErrorToken, buildUnexpectedCharacterToken; | 29 show ErrorToken, buildUnexpectedCharacterToken; |
32 | 30 |
33 export 'scanner/token_constants.dart' show EOF_TOKEN; | 31 export 'scanner/token_constants.dart' show EOF_TOKEN; |
34 | 32 |
35 export 'scanner/utf8_bytes_scanner.dart' show Utf8BytesScanner; | 33 export 'scanner/utf8_bytes_scanner.dart' show Utf8BytesScanner; |
36 | 34 |
37 export 'scanner/string_scanner.dart' show StringScanner; | 35 export 'scanner/string_scanner.dart' show StringScanner; |
38 | 36 |
39 export '../scanner/token.dart' show Keyword; | 37 export '../scanner/token.dart' show Keyword, Token; |
40 | 38 |
41 const int unicodeReplacementCharacter = UNICODE_REPLACEMENT_CHARACTER_RUNE; | 39 const int unicodeReplacementCharacter = UNICODE_REPLACEMENT_CHARACTER_RUNE; |
42 | 40 |
43 typedef Token Recover(List<int> bytes, Token tokens, List<int> lineStarts); | 41 typedef Token Recover(List<int> bytes, Token tokens, List<int> lineStarts); |
44 | 42 |
45 abstract class Scanner { | 43 abstract class Scanner { |
46 /// Returns true if an error occured during [tokenize]. | 44 /// Returns true if an error occured during [tokenize]. |
47 bool get hasErrors; | 45 bool get hasErrors; |
48 | 46 |
49 List<int> get lineStarts; | 47 List<int> get lineStarts; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 ScannerResult _tokenizeAndRecover(Scanner scanner, Recover recover, | 88 ScannerResult _tokenizeAndRecover(Scanner scanner, Recover recover, |
91 {List<int> bytes, String source}) { | 89 {List<int> bytes, String source}) { |
92 Token tokens = scanner.tokenize(); | 90 Token tokens = scanner.tokenize(); |
93 if (scanner.hasErrors) { | 91 if (scanner.hasErrors) { |
94 if (bytes == null) bytes = UTF8.encode(source); | 92 if (bytes == null) bytes = UTF8.encode(source); |
95 recover ??= defaultRecoveryStrategy; | 93 recover ??= defaultRecoveryStrategy; |
96 tokens = recover(bytes, tokens, scanner.lineStarts); | 94 tokens = recover(bytes, tokens, scanner.lineStarts); |
97 } | 95 } |
98 return new ScannerResult(tokens, scanner.lineStarts, scanner.hasErrors); | 96 return new ScannerResult(tokens, scanner.lineStarts, scanner.hasErrors); |
99 } | 97 } |
OLD | NEW |