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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 load(String yaml) {
27 var stream = loadStream(yaml);
28 if (stream.length != 1) {
29 throw new Error("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 loadStream(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 Error implements Exception {
50 String msg;
51
52 Error(this.msg);
53
54 String toString() => msg;
55 }
OLDNEW
« 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