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 import 'dart:collection' show Queue; | |
9 | |
10 import 'deep_equals.dart'; | |
11 | |
12 part 'yaml_map.dart'; | |
13 part 'model.dart'; | |
14 part 'parser.dart'; | |
15 part 'visitor.dart'; | |
16 part 'composer.dart'; | |
17 part 'constructor.dart'; | |
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 | |
25 /// are YamlMaps. These have a few small behavioral differences from the default | |
26 /// Map implementation; for details, see the YamlMap class. | |
27 loadYaml(String yaml) { | |
28 var stream = loadYamlStream(yaml); | |
29 if (stream.length != 1) { | |
30 throw new YamlException("Expected 1 document, were ${stream.length}"); | |
31 } | |
32 return stream[0]; | |
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 | |
40 /// are YamlMaps. These have a few small behavioral differences from the default | |
41 /// Map implementation; for details, see the YamlMap class. | |
42 List loadYamlStream(String yaml) { | |
43 return new _Parser(yaml).l_yamlStream().mappedBy((doc) => | |
44 new _Constructor(new _Composer(doc).compose()).construct()) | |
45 .toList(); | |
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 |