Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Unified Diff: utils/yaml/yaml.dart

Issue 10153004: Add a basic YAML processor. Much of the language is still unimplemented. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: utils/yaml/yaml.dart
diff --git a/utils/yaml/yaml.dart b/utils/yaml/yaml.dart
new file mode 100644
index 0000000000000000000000000000000000000000..37d564eb3c295068ba44b3c2b73f6af6a9e7aa47
--- /dev/null
+++ b/utils/yaml/yaml.dart
@@ -0,0 +1,55 @@
+// 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");
+
+#import("deep_equals.dart");
+
+#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) {
+ return new _Parser(yaml).l_yamlStream().map((doc) =>
+ new _Constructor(new _Composer(doc).compose()).construct());
+}
+
+/** An error thrown by the YAML processor. */
+class Error implements Exception {
+ String msg;
+
+ Error(this.msg);
+
+ String toString() => msg;
+}
« utils/yaml/parser.dart ('K') | « utils/yaml/visitor.dart ('k') | utils/yaml/yaml_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698