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