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