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

Unified Diff: pkg/yaml/lib/yaml.dart

Issue 302313007: Attach source range information to parsed YAML nodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix tests Created 6 years, 7 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
« no previous file with comments | « pkg/yaml/lib/src/yaml_node.dart ('k') | pkg/yaml/test/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/yaml/lib/yaml.dart
diff --git a/pkg/yaml/lib/yaml.dart b/pkg/yaml/lib/yaml.dart
index 209db8c3b8652375c66713cccd051d71f7f080f0..f59719d638066f1a1fc3d93472f65bef81404095 100644
--- a/pkg/yaml/lib/yaml.dart
+++ b/pkg/yaml/lib/yaml.dart
@@ -8,9 +8,10 @@ import 'src/composer.dart';
import 'src/constructor.dart';
import 'src/parser.dart';
import 'src/yaml_exception.dart';
+import 'src/yaml_node.dart';
export 'src/yaml_exception.dart';
-export 'src/yaml_map.dart';
+export 'src/yaml_node.dart';
/// Loads a single document from a YAML string.
///
@@ -28,12 +29,20 @@ export 'src/yaml_map.dart';
///
/// If [sourceName] is passed, it's used as the name of the file or URL from
/// which the YAML originated for error reporting.
-loadYaml(String yaml, {String sourceName}) {
+loadYaml(String yaml, {String sourceName}) =>
+ loadYamlNode(yaml, sourceName: sourceName).value;
+
+/// Loads a single document from a YAML string as a [YamlNode].
+///
+/// This is just like [loadYaml], except that where [loadYaml] would return a
+/// normal Dart value this returns a [YamlNode] instead. This allows the caller
+/// to be confident that the return value will always be a [YamlNode].
+YamlNode loadYamlNode(String yaml, {String sourceName}) {
var stream = loadYamlStream(yaml, sourceName: sourceName);
if (stream.length != 1) {
throw new YamlException("Expected 1 document, were ${stream.length}.");
}
- return stream[0];
+ return stream.nodes[0];
}
/// Loads a stream of documents from a YAML string.
@@ -49,15 +58,16 @@ loadYaml(String yaml, {String sourceName}) {
///
/// If [sourceName] is passed, it's used as the name of the file or URL from
/// which the YAML originated for error reporting.
-List loadYamlStream(String yaml, {String sourceName}) {
- var stream;
+YamlList loadYamlStream(String yaml, {String sourceName}) {
+ var pair;
try {
- stream = new Parser(yaml, sourceName).l_yamlStream();
+ pair = new Parser(yaml, sourceName).l_yamlStream();
} on FormatException catch (error) {
throw new YamlException(error.toString());
}
- return stream
+ var nodes = pair.first
.map((doc) => new Constructor(new Composer(doc).compose()).construct())
.toList();
+ return new YamlList(nodes, pair.last);
}
« no previous file with comments | « pkg/yaml/lib/src/yaml_node.dart ('k') | pkg/yaml/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698