| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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; | 5 library yaml; |
| 6 | 6 |
| 7 import 'dart:math' as Math; | 7 import 'dart:math' as Math; |
| 8 | 8 |
| 9 import 'deep_equals.dart'; | 9 import 'deep_equals.dart'; |
| 10 | 10 |
| 11 part 'yaml_map.dart'; | 11 part 'yaml_map.dart'; |
| 12 part 'model.dart'; | 12 part 'model.dart'; |
| 13 part 'parser.dart'; | 13 part 'parser.dart'; |
| 14 part 'visitor.dart'; | 14 part 'visitor.dart'; |
| 15 part 'composer.dart'; | 15 part 'composer.dart'; |
| 16 part 'constructor.dart'; | 16 part 'constructor.dart'; |
| 17 | 17 |
| 18 /** | 18 /// Loads a single document from a YAML string. If the string contains more than |
| 19 * Loads a single document from a YAML string. If the string contains more than | 19 /// one document, this throws an error. |
| 20 * one document, this throws an error. | 20 /// |
| 21 * | 21 /// The return value is mostly normal Dart objects. However, since YAML mappings |
| 22 * The return value is mostly normal Dart objects. However, since YAML mappings | 22 /// support some key types that the default Dart map implementation doesn't |
| 23 * support some key types that the default Dart map implementation doesn't | 23 /// (null, NaN, booleans, lists, and maps), all maps in the returned document |
| 24 * (null, NaN, booleans, lists, and maps), all maps in the returned document are | 24 /// are YamlMaps. These have a few small behavioral differences from the default |
| 25 * YamlMaps. These have a few small behavioral differences from the default Map | 25 /// Map implementation; for details, see the YamlMap class. |
| 26 * implementation; for details, see the YamlMap class. | |
| 27 */ | |
| 28 loadYaml(String yaml) { | 26 loadYaml(String yaml) { |
| 29 var stream = loadYamlStream(yaml); | 27 var stream = loadYamlStream(yaml); |
| 30 if (stream.length != 1) { | 28 if (stream.length != 1) { |
| 31 throw new YamlException("Expected 1 document, were ${stream.length}"); | 29 throw new YamlException("Expected 1 document, were ${stream.length}"); |
| 32 } | 30 } |
| 33 return stream[0]; | 31 return stream[0]; |
| 34 } | 32 } |
| 35 | 33 |
| 36 /** | 34 /// Loads a stream of documents from a YAML string. |
| 37 * Loads a stream of documents from a YAML string. | 35 /// |
| 38 * | 36 /// The return value is mostly normal Dart objects. However, since YAML mappings |
| 39 * The return value is mostly normal Dart objects. However, since YAML mappings | 37 /// support some key types that the default Dart map implementation doesn't |
| 40 * support some key types that the default Dart map implementation doesn't | 38 /// (null, NaN, booleans, lists, and maps), all maps in the returned document |
| 41 * (null, NaN, booleans, lists, and maps), all maps in the returned document are | 39 /// are YamlMaps. These have a few small behavioral differences from the default |
| 42 * YamlMaps. These have a few small behavioral differences from the default Map | 40 /// Map implementation; for details, see the YamlMap class. |
| 43 * implementation; for details, see the YamlMap class. | |
| 44 */ | |
| 45 List loadYamlStream(String yaml) { | 41 List loadYamlStream(String yaml) { |
| 46 return new _Parser(yaml).l_yamlStream().map((doc) => | 42 return new _Parser(yaml).l_yamlStream().map((doc) => |
| 47 new _Constructor(new _Composer(doc).compose()).construct()); | 43 new _Constructor(new _Composer(doc).compose()).construct()); |
| 48 } | 44 } |
| 49 | 45 |
| 50 /** An error thrown by the YAML processor. */ | 46 /// An error thrown by the YAML processor. |
| 51 class YamlException implements Exception { | 47 class YamlException implements Exception { |
| 52 String msg; | 48 String msg; |
| 53 | 49 |
| 54 YamlException(this.msg); | 50 YamlException(this.msg); |
| 55 | 51 |
| 56 String toString() => msg; | 52 String toString() => msg; |
| 57 } | 53 } |
| OLD | NEW |