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 engine.incremental_scanner; | 5 library engine.incremental_scanner; |
6 | 6 |
7 import "dart:math" as math; | 7 import "dart:math" as math; |
8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 |
9 import 'error.dart'; | 11 import 'error.dart'; |
10 import 'scanner.dart'; | 12 import 'scanner.dart'; |
11 import 'source.dart'; | 13 import 'source.dart'; |
12 import 'utilities_collection.dart' show TokenMap; | 14 import 'utilities_collection.dart' show TokenMap; |
13 | 15 |
14 /** | 16 /** |
15 * An `IncrementalScanner` is a scanner that scans a subset of a string and | 17 * An `IncrementalScanner` is a scanner that scans a subset of a string and |
16 * inserts the resulting tokens into the middle of an existing token stream. | 18 * inserts the resulting tokens into the middle of an existing token stream. |
17 */ | 19 */ |
18 class IncrementalScanner { | 20 class IncrementalScanner { |
19 /** | 21 /** |
20 * The source being scanned. | 22 * The source being scanned. |
21 */ | 23 */ |
22 final Source source; | 24 final Source source; |
23 | 25 |
24 /** | 26 /** |
25 * The reader used to access the characters in the source. | 27 * The reader used to access the characters in the source. |
26 */ | 28 */ |
27 final CharacterReader reader; | 29 final CharacterReader reader; |
28 | 30 |
29 /** | 31 /** |
30 * The error listener that will be informed of any errors that are found | 32 * The error listener that will be informed of any errors that are found |
31 * during the scan. | 33 * during the scan. |
32 * | 34 * |
33 * TODO(brianwilkerson) Replace this with a list of errors so that we can | 35 * TODO(brianwilkerson) Replace this with a list of errors so that we can |
34 * update the errors. | 36 * update the errors. |
35 */ | 37 */ |
36 final AnalysisErrorListener errorListener; | 38 final AnalysisErrorListener errorListener; |
37 | 39 |
| 40 final AnalysisOptions _options; |
| 41 |
38 /** | 42 /** |
39 * A map from tokens that were copied to the copies of the tokens. | 43 * A map from tokens that were copied to the copies of the tokens. |
40 */ | 44 */ |
41 TokenMap _tokenMap = new TokenMap(); | 45 TokenMap _tokenMap = new TokenMap(); |
42 | 46 |
43 /** | 47 /** |
44 * The token immediately to the left of the range of tokens that were | 48 * The token immediately to the left of the range of tokens that were |
45 * modified. | 49 * modified. |
46 */ | 50 */ |
47 Token leftToken; | 51 Token leftToken; |
48 | 52 |
49 /** | 53 /** |
50 * The token immediately to the right of the range of tokens that were | 54 * The token immediately to the right of the range of tokens that were |
51 * modified. | 55 * modified. |
52 */ | 56 */ |
53 Token rightToken; | 57 Token rightToken; |
54 | 58 |
55 /** | 59 /** |
56 * A flag indicating whether there were any non-comment tokens changed (other | 60 * A flag indicating whether there were any non-comment tokens changed (other |
57 * than having their position updated) as a result of the modification. | 61 * than having their position updated) as a result of the modification. |
58 */ | 62 */ |
59 bool hasNonWhitespaceChange = false; | 63 bool hasNonWhitespaceChange = false; |
60 | 64 |
61 /** | 65 /** |
62 * Initialize a newly created scanner to scan characters within the given | 66 * Initialize a newly created scanner to scan characters within the given |
63 * [source]. The content of the source can be read using the given [reader]. | 67 * [source]. The content of the source can be read using the given [reader]. |
64 * Any errors that are found will be reported to the given [errorListener]. | 68 * Any errors that are found will be reported to the given [errorListener]. |
| 69 * [_options] will determine how scanning is to be performed. |
65 */ | 70 */ |
66 IncrementalScanner(this.source, this.reader, this.errorListener); | 71 IncrementalScanner( |
| 72 this.source, this.reader, this.errorListener, this._options); |
67 | 73 |
68 /** | 74 /** |
69 * Return a map from tokens that were copied to the copies of the tokens. | 75 * Return a map from tokens that were copied to the copies of the tokens. |
70 * | 76 * |
71 * @return a map from tokens that were copied to the copies of the tokens | 77 * @return a map from tokens that were copied to the copies of the tokens |
72 */ | 78 */ |
73 TokenMap get tokenMap => _tokenMap; | 79 TokenMap get tokenMap => _tokenMap; |
74 | 80 |
75 /** | 81 /** |
76 * Given the [stream] of tokens scanned from the original source, the modified | 82 * Given the [stream] of tokens scanned from the original source, the modified |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return token; | 217 return token; |
212 } | 218 } |
213 | 219 |
214 /** | 220 /** |
215 * Scan the token between the [start] (inclusive) and [end] (exclusive) | 221 * Scan the token between the [start] (inclusive) and [end] (exclusive) |
216 * offsets. | 222 * offsets. |
217 */ | 223 */ |
218 Token _scanRange(int start, int end) { | 224 Token _scanRange(int start, int end) { |
219 Scanner scanner = new Scanner( | 225 Scanner scanner = new Scanner( |
220 source, new CharacterRangeReader(reader, start, end), errorListener); | 226 source, new CharacterRangeReader(reader, start, end), errorListener); |
| 227 scanner.enableNullAwareOperators = _options.enableNullAwareOperators; |
221 return scanner.tokenize(); | 228 return scanner.tokenize(); |
222 } | 229 } |
223 | 230 |
224 /** | 231 /** |
225 * Update the offsets of every token from the given [token] to the end of the | 232 * Update the offsets of every token from the given [token] to the end of the |
226 * stream by adding the given [delta]. | 233 * stream by adding the given [delta]. |
227 */ | 234 */ |
228 void _updateOffsets(Token token, int delta) { | 235 void _updateOffsets(Token token, int delta) { |
229 while (token.type != TokenType.EOF) { | 236 while (token.type != TokenType.EOF) { |
230 _tokenMap.put(token, token); | 237 _tokenMap.put(token, token); |
231 token.offset += delta; | 238 token.offset += delta; |
232 Token comment = token.precedingComments; | 239 Token comment = token.precedingComments; |
233 while (comment != null) { | 240 while (comment != null) { |
234 comment.offset += delta; | 241 comment.offset += delta; |
235 comment = comment.next; | 242 comment = comment.next; |
236 } | 243 } |
237 token = token.next; | 244 token = token.next; |
238 } | 245 } |
239 _tokenMap.put(token, token); | 246 _tokenMap.put(token, token); |
240 token.offset += delta; | 247 token.offset += delta; |
241 } | 248 } |
242 } | 249 } |
OLD | NEW |