| 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 yaml.scanner; | |
| 6 | |
| 7 import 'package:collection/collection.dart'; | 5 import 'package:collection/collection.dart'; |
| 8 import 'package:string_scanner/string_scanner.dart'; | 6 import 'package:string_scanner/string_scanner.dart'; |
| 9 import 'package:source_span/source_span.dart'; | 7 import 'package:source_span/source_span.dart'; |
| 10 | 8 |
| 11 import 'style.dart'; | 9 import 'style.dart'; |
| 12 import 'token.dart'; | 10 import 'token.dart'; |
| 13 import 'utils.dart'; | 11 import 'utils.dart'; |
| 14 import 'yaml_exception.dart'; | 12 import 'yaml_exception.dart'; |
| 15 | 13 |
| 16 /// A scanner that reads a string of Unicode characters and emits [Token]s. | 14 /// A scanner that reads a string of Unicode characters and emits [Token]s. |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if (!_tokenAvailable) _fetchMoreTokens(); | 317 if (!_tokenAvailable) _fetchMoreTokens(); |
| 320 return _tokens.first; | 318 return _tokens.first; |
| 321 } | 319 } |
| 322 | 320 |
| 323 /// Ensures that [_tokens] contains at least one token which can be returned. | 321 /// Ensures that [_tokens] contains at least one token which can be returned. |
| 324 void _fetchMoreTokens() { | 322 void _fetchMoreTokens() { |
| 325 while (true) { | 323 while (true) { |
| 326 if (_tokens.isNotEmpty) { | 324 if (_tokens.isNotEmpty) { |
| 327 _staleSimpleKeys(); | 325 _staleSimpleKeys(); |
| 328 | 326 |
| 327 // If there are no more tokens to fetch, break. |
| 328 if (_tokens.last.type == TokenType.STREAM_END) break; |
| 329 |
| 329 // If the current token could be a simple key, we need to scan more | 330 // If the current token could be a simple key, we need to scan more |
| 330 // tokens until we determine whether it is or not. Otherwise we might | 331 // tokens until we determine whether it is or not. Otherwise we might |
| 331 // not emit the `KEY` token before we emit the value of the key. | 332 // not emit the `KEY` token before we emit the value of the key. |
| 332 if (!_simpleKeys.any((key) => | 333 if (!_simpleKeys.any((key) => |
| 333 key != null && key.tokenNumber == _tokensParsed)) { | 334 key != null && key.tokenNumber == _tokensParsed)) { |
| 334 break; | 335 break; |
| 335 } | 336 } |
| 336 } | 337 } |
| 337 | 338 |
| 338 _fetchNextToken(); | 339 _fetchNextToken(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } else { | 456 } else { |
| 456 _fetchValue(); | 457 _fetchValue(); |
| 457 } | 458 } |
| 458 return; | 459 return; |
| 459 default: | 460 default: |
| 460 if (!_isNonBreak) _invalidScalarCharacter(); | 461 if (!_isNonBreak) _invalidScalarCharacter(); |
| 461 | 462 |
| 462 _fetchPlainScalar(); | 463 _fetchPlainScalar(); |
| 463 return; | 464 return; |
| 464 } | 465 } |
| 465 | |
| 466 throw 'Inaccessible'; | |
| 467 } | 466 } |
| 468 | 467 |
| 469 /// Throws an error about a disallowed character. | 468 /// Throws an error about a disallowed character. |
| 470 void _invalidScalarCharacter() => | 469 void _invalidScalarCharacter() => |
| 471 _scanner.error("Unexpected character.", length: 1); | 470 _scanner.error("Unexpected character.", length: 1); |
| 472 | 471 |
| 473 /// Checks the list of potential simple keys and remove the positions that | 472 /// Checks the list of potential simple keys and remove the positions that |
| 474 /// cannot contain simple keys anymore. | 473 /// cannot contain simple keys anymore. |
| 475 void _staleSimpleKeys() { | 474 void _staleSimpleKeys() { |
| 476 for (var i = 0; i < _simpleKeys.length; i++) { | 475 for (var i = 0; i < _simpleKeys.length; i++) { |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 | 1674 |
| 1676 /// All trailing whitespace is preserved. | 1675 /// All trailing whitespace is preserved. |
| 1677 static const KEEP = const _Chomping("KEEP"); | 1676 static const KEEP = const _Chomping("KEEP"); |
| 1678 | 1677 |
| 1679 final String name; | 1678 final String name; |
| 1680 | 1679 |
| 1681 const _Chomping(this.name); | 1680 const _Chomping(this.name); |
| 1682 | 1681 |
| 1683 String toString() => name; | 1682 String toString() => name; |
| 1684 } | 1683 } |
| OLD | NEW |