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

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: code review 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/parser.dart ('k') | pkg/yaml/pubspec.yaml » ('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 dc895e655c60bf770ab7572664ed3a0b77b25c13..209db8c3b8652375c66713cccd051d71f7f080f0 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);
+///
+/// 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}) {
+ 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()
+///
+/// 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;
+ 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();
}
« no previous file with comments | « pkg/yaml/lib/src/parser.dart ('k') | pkg/yaml/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698