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

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

Issue 308743007: Use SpanScanner to emit better YAML parse errors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: dependency pubspec updates 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
Index: pkg/yaml/lib/yaml.dart
diff --git a/pkg/yaml/lib/yaml.dart b/pkg/yaml/lib/yaml.dart
index dc895e655c60bf770ab7572664ed3a0b77b25c13..85a25df16e140b54104956e663fc66dfe42194db 100644
--- a/pkg/yaml/lib/yaml.dart
+++ b/pkg/yaml/lib/yaml.dart
@@ -25,8 +25,11 @@ export 'src/yaml_map.dart';
///
/// In future versions, maps will instead be [HashMap]s with a custom equality
/// operation.
-loadYaml(String yaml) {
- var stream = loadYamlStream(yaml);
+///
+/// [sourceName] is the name of the file or URL from which the YAML originated.
+/// It's used for error reporting.
Bob Nystrom 2014/05/30 16:32:39 I think it would be good to explicitly mention tha
nweiz 2014/06/02 18:36:14 Done.
+loadYaml(String yaml, {String sourceName}) {
+ var stream = loadYamlStream(yaml, sourceName: sourceName);
if (stream.length != 1) {
throw new YamlException("Expected 1 document, were ${stream.length}.");
}
@@ -43,8 +46,18 @@ loadYaml(String yaml) {
///
/// In future versions, maps will instead be [HashMap]s with a custom equality
/// operation.
-List loadYamlStream(String yaml) {
- return new Parser(yaml).l_yamlStream()
+///
+/// [sourceName] is the name of the file or URL from which the YAML originated.
+/// It's used for error reporting.
Bob Nystrom 2014/05/30 16:32:39 Here too.
nweiz 2014/06/02 18:36:14 Done.
+List loadYamlStream(String yaml, {String sourceName}) {
+ var stream;
+ try {
+ stream = new Parser(yaml, sourceName).l_yamlStream();
+ } on FormatException catch (error) {
+ throw new YamlException(error.toString());
+ }
+
+ return stream
.map((doc) => new Constructor(new Composer(doc).compose()).construct())
.toList();
}

Powered by Google App Engine
This is Rietveld 408576698