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