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

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: 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/composer.dart ('k') | pkg/yaml/lib/src/deep_equals.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a8224a493868191241b5ecbb94e12f730257f62d 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,54 @@ 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.
- visitMapping(MappingNode map) {
+ /// Converts a mapping into a [Map] of Dart objects.
+ 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
- /// thing exists.
- getAnchor(Node anchored) {
+ /// Returns a new Dart object wrapping the object that already represents
+ /// [anchored], if such a thing exists.
+ YamlNode getAnchor(Node anchored) {
if (anchored.anchor == null) return null;
- if (_anchors.containsKey(anchored.anchor)) return _anchors[anchored.anchor];
+ var value = _anchors[anchored.anchor];
+ if (vaule == null) return null;
+
+ // Re-wrap [value]'s contents so that it's associated with the span of the
+ // anchor rather than its original definition.
+ 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;
« no previous file with comments | « pkg/yaml/lib/src/composer.dart ('k') | pkg/yaml/lib/src/deep_equals.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698