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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 export 'scanner/error_token.dart' | 30 export 'scanner/error_token.dart' |
31 show ErrorToken, buildUnexpectedCharacterToken; | 31 show ErrorToken, buildUnexpectedCharacterToken; |
32 | 32 |
33 export 'scanner/token_constants.dart' show EOF_TOKEN; | 33 export 'scanner/token_constants.dart' show EOF_TOKEN; |
34 | 34 |
35 export 'scanner/utf8_bytes_scanner.dart' show Utf8BytesScanner; | 35 export 'scanner/utf8_bytes_scanner.dart' show Utf8BytesScanner; |
36 | 36 |
37 export 'scanner/string_scanner.dart' show StringScanner; | 37 export 'scanner/string_scanner.dart' show StringScanner; |
38 | 38 |
39 export 'scanner/keyword.dart' show Keyword; | 39 export '../scanner/token.dart' show Keyword; |
40 | 40 |
41 const int unicodeReplacementCharacter = UNICODE_REPLACEMENT_CHARACTER_RUNE; | 41 const int unicodeReplacementCharacter = UNICODE_REPLACEMENT_CHARACTER_RUNE; |
42 | 42 |
43 typedef Token Recover(List<int> bytes, Token tokens, List<int> lineStarts); | 43 typedef Token Recover(List<int> bytes, Token tokens, List<int> lineStarts); |
44 | 44 |
45 abstract class Scanner { | 45 abstract class Scanner { |
46 /// Returns true if an error occured during [tokenize]. | 46 /// Returns true if an error occured during [tokenize]. |
47 bool get hasErrors; | 47 bool get hasErrors; |
48 | 48 |
49 List<int> get lineStarts; | 49 List<int> get lineStarts; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ScannerResult _tokenizeAndRecover(Scanner scanner, Recover recover, | 84 ScannerResult _tokenizeAndRecover(Scanner scanner, Recover recover, |
85 {List<int> bytes, String source}) { | 85 {List<int> bytes, String source}) { |
86 Token tokens = scanner.tokenize(); | 86 Token tokens = scanner.tokenize(); |
87 if (scanner.hasErrors) { | 87 if (scanner.hasErrors) { |
88 if (bytes == null) bytes = UTF8.encode(source); | 88 if (bytes == null) bytes = UTF8.encode(source); |
89 recover ??= defaultRecoveryStrategy; | 89 recover ??= defaultRecoveryStrategy; |
90 tokens = recover(bytes, tokens, scanner.lineStarts); | 90 tokens = recover(bytes, tokens, scanner.lineStarts); |
91 } | 91 } |
92 return new ScannerResult(tokens, scanner.lineStarts, scanner.hasErrors); | 92 return new ScannerResult(tokens, scanner.lineStarts, scanner.hasErrors); |
93 } | 93 } |
OLD | NEW |