Chromium Code Reviews| Index: lib/yaml/yaml.dart |
| diff --git a/lib/yaml/yaml.dart b/lib/yaml/yaml.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..99af2b4f44256b85b48d2773dc25a116246adb08 |
| --- /dev/null |
| +++ b/lib/yaml/yaml.dart |
| @@ -0,0 +1,54 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#library("yaml"); |
| + |
| +#source("yaml_map.dart"); |
| +#source("model.dart"); |
| +#source("parser.dart"); |
| +#source("visitor.dart"); |
| +#source("composer.dart"); |
| +#source("constructor.dart"); |
| + |
| +/** |
| + * Loads a single document from a YAML string. If the string contains more than |
| + * one document, this throws an error. |
| + * |
| + * The return value is mostly normal Dart objects. However, since YAML mappings |
| + * support some key types that the default Dart map implementation doesn't |
| + * (null, NaN, booleans, lists, and maps), all maps in the returned document are |
| + * YamlMaps. These have a few small behavioral differences from the default Map |
| + * implementation; for details, see the YamlMap class. |
| + */ |
| +load(String yaml) { |
| + var stream = loadStream(yaml); |
| + if (stream.length != 1) { |
| + throw new Error("Expected 1 document, were ${stream.length}"); |
| + } |
| + return stream[0]; |
| +} |
| + |
| +/** |
| + * Loads a stream of documents from a YAML string. |
| + * |
| + * The return value is mostly normal Dart objects. However, since YAML mappings |
| + * support some key types that the default Dart map implementation doesn't |
| + * (null, NaN, booleans, lists, and maps), all maps in the returned document are |
| + * YamlMaps. These have a few small behavioral differences from the default Map |
| + * implementation; for details, see the YamlMap class. |
| + */ |
| +List loadStream(String yaml) { |
| + var tok = new _Parser(yaml); |
| + return tok._l_yamlStream().map((doc) => |
| + new _Constructor(new _Composer(doc).compose()).construct()); |
| +} |
| + |
| +/** An error thrown by the YAML processor. */ |
| +class Error implements Exception { |
|
Bob Nystrom
2012/04/20 20:28:55
"YamlException"
nweiz
2012/04/23 23:06:33
I expect people to implement this library with a p
Bob Nystrom
2012/04/24 00:50:36
Hmm, we should discuss this offline. So far, we ve
nweiz
2012/04/25 00:26:29
Done, although I'd rather see a more principled na
|
| + String _msg; |
| + |
| + Error(String this._msg); |
| + |
| + String toString() => _msg; |
| +} |