OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.src.dart.scanner.scanner; | 5 library analyzer.src.dart.scanner.scanner; |
6 | 6 |
7 import 'package:analyzer/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
8 import 'package:analyzer/error/listener.dart'; | 8 import 'package:analyzer/error/listener.dart'; |
9 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; | 9 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 /** | 42 /** |
43 * Initialize a newly created scanner to scan characters from the given | 43 * Initialize a newly created scanner to scan characters from the given |
44 * [source]. The given character [reader] will be used to read the characters | 44 * [source]. The given character [reader] will be used to read the characters |
45 * in the source. The given [_errorListener] will be informed of any errors | 45 * in the source. The given [_errorListener] will be informed of any errors |
46 * that are found. | 46 * that are found. |
47 */ | 47 */ |
48 factory Scanner(Source source, CharacterReader reader, | 48 factory Scanner(Source source, CharacterReader reader, |
49 AnalysisErrorListener errorListener) => | 49 AnalysisErrorListener errorListener) => |
50 fe.Scanner.useFasta | 50 fe.Scanner.useFasta |
51 ? new _Scanner2( | 51 ? new Scanner.fasta(source, errorListener, |
52 source, reader.getContents(), reader.offset, errorListener) | 52 contents: reader.getContents(), offset: reader.offset) |
53 : new Scanner._(source, reader, errorListener); | 53 : new Scanner._(source, reader, errorListener); |
54 | 54 |
| 55 factory Scanner.fasta(Source source, AnalysisErrorListener errorListener, |
| 56 {String contents, int offset: 0}) { |
| 57 return new _Scanner2( |
| 58 source, contents ?? source.contents.data, offset, errorListener); |
| 59 } |
| 60 |
55 Scanner._(this.source, CharacterReader reader, this._errorListener) | 61 Scanner._(this.source, CharacterReader reader, this._errorListener) |
56 : super.create(reader); | 62 : super.create(reader); |
57 | 63 |
58 @override | 64 @override |
59 void reportError( | 65 void reportError( |
60 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 66 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
61 _errorListener | 67 _errorListener |
62 .onError(new AnalysisError(source, offset, 1, errorCode, arguments)); | 68 .onError(new AnalysisError(source, offset, 1, errorCode, arguments)); |
63 } | 69 } |
64 } | 70 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (_readerOffset != -1) { | 190 if (_readerOffset != -1) { |
185 final int delta = _readerOffset + 1; | 191 final int delta = _readerOffset + 1; |
186 do { | 192 do { |
187 token.offset += delta; | 193 token.offset += delta; |
188 token = token.next; | 194 token = token.next; |
189 } while (!token.isEof); | 195 } while (!token.isEof); |
190 } | 196 } |
191 return firstToken; | 197 return firstToken; |
192 } | 198 } |
193 } | 199 } |
OLD | NEW |