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

Unified Diff: pkg/yaml/lib/src/constructor.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: 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/src/constructor.dart
diff --git a/pkg/yaml/lib/src/constructor.dart b/pkg/yaml/lib/src/constructor.dart
index 116809dfb6ad3d4a4c2f3dfaf3659c001987beb7..b77c38b597b51dba65e05c8d28c56ac9ce4b7d92 100644
--- a/pkg/yaml/lib/src/constructor.dart
+++ b/pkg/yaml/lib/src/constructor.dart
@@ -4,9 +4,10 @@
library yaml.constructor;
+import 'equality.dart';
import 'model.dart';
import 'visitor.dart';
-import 'yaml_map.dart';
+import 'yaml_node.dart';
/// Takes a parsed and composed YAML document (what the spec calls the
/// "representation graph") and creates native Dart objects that represent that
@@ -16,43 +17,52 @@ class Constructor extends Visitor {
final Node _root;
/// Map from anchor names to the most recent Dart node with that anchor.
- final _anchors = <String, dynamic>{};
+ final _anchors = <String, YamlNode>{};
Constructor(this._root);
/// Runs the Constructor to produce a Dart object.
- construct() => _root.visit(this);
+ YamlNode construct() => _root.visit(this);
/// Returns the value of a scalar.
- visitScalar(ScalarNode scalar) => scalar.value;
+ YamlScalar visitScalar(ScalarNode scalar) =>
+ new YamlScalar(scalar.value, scalar.span);
/// Converts a sequence into a List of Dart objects.
- visitSequence(SequenceNode seq) {
+ YamlList visitSequence(SequenceNode seq) {
var anchor = getAnchor(seq);
if (anchor != null) return anchor;
- var dartSeq = setAnchor(seq, []);
- dartSeq.addAll(super.visitSequence(seq));
+ var nodes = [];
+ var dartSeq = setAnchor(seq, new YamlList(nodes, seq.span));
+ nodes.addAll(super.visitSequence(seq));
return dartSeq;
}
/// Converts a mapping into a Map of Dart objects.
Bob Nystrom 2014/06/03 00:33:14 "Map" -> "[Map]".
nweiz 2014/06/03 02:03:21 Done.
- visitMapping(MappingNode map) {
+ YamlMap visitMapping(MappingNode map) {
var anchor = getAnchor(map);
if (anchor != null) return anchor;
- var dartMap = setAnchor(map, new YamlMap());
- super.visitMapping(map).forEach((k, v) { dartMap[k] = v; });
+ var nodes = deepEqualsMap();
+ var dartMap = setAnchor(map, new YamlMap(nodes, map.span));
+ super.visitMapping(map).forEach((k, v) => nodes[k] = v);
return dartMap;
}
/// Returns the Dart object that already represents [anchored], if such a
Bob Nystrom 2014/06/03 00:33:14 This is a bit confusing since it's a new object no
nweiz 2014/06/03 02:03:21 Done.
/// thing exists.
- getAnchor(Node anchored) {
+ YamlNode getAnchor(Node anchored) {
if (anchored.anchor == null) return null;
- if (_anchors.containsKey(anchored.anchor)) return _anchors[anchored.anchor];
+ if (!_anchors.containsKey(anchored.anchor)) return null;
+
+ var value = _anchors[anchored.anchor];
Bob Nystrom 2014/06/03 00:33:14 Can this ever be null now? If not, use it for the
Bob Nystrom 2014/06/03 00:33:14 Add a comment explaining why these are copied. Is
nweiz 2014/06/03 02:03:21 Done.
nweiz 2014/06/03 02:03:21 Done.
+ if (value is YamlMap) return new YamlMap(value.nodes, anchored.span);
+ if (value is YamlList) return new YamlList(value.nodes, anchored.span);
+ assert(value is YamlScalar);
+ return new YamlScalar(value.value, anchored.span);
}
/// Records that [value] is the Dart object representing [anchored].
- setAnchor(Node anchored, value) {
+ YamlNode setAnchor(Node anchored, YamlNode value) {
if (anchored.anchor == null) return value;
_anchors[anchored.anchor] = value;
return value;

Powered by Google App Engine
This is Rietveld 408576698