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

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

Issue 689513002: Rewrite the pkg/yaml parser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 1 month 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/event.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
deleted file mode 100644
index 5931dae01966571edde60f7c3d86f3e850486660..0000000000000000000000000000000000000000
--- a/pkg/yaml/lib/src/constructor.dart
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library yaml.constructor;
-
-import 'equality.dart';
-import 'model.dart';
-import 'visitor.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
-/// document.
-class Constructor extends Visitor {
- /// The root node of the representation graph.
- final Node _root;
-
- /// Map from anchor names to the most recent Dart node with that anchor.
- final _anchors = <String, YamlNode>{};
-
- Constructor(this._root);
-
- /// Runs the Constructor to produce a Dart object.
- YamlNode construct() => _root.visit(this);
-
- /// Returns the value of a scalar.
- YamlScalar visitScalar(ScalarNode scalar) =>
- new YamlScalar.internal(scalar.value, scalar.span);
-
- /// Converts a sequence into a List of Dart objects.
- YamlList visitSequence(SequenceNode seq) {
- var anchor = getAnchor(seq);
- if (anchor != null) return anchor;
- var nodes = [];
- var dartSeq = setAnchor(seq, new YamlList.internal(nodes, seq.span));
- nodes.addAll(super.visitSequence(seq));
- return dartSeq;
- }
-
- /// Converts a mapping into a [Map] of Dart objects.
- YamlMap visitMapping(MappingNode map) {
- var anchor = getAnchor(map);
- if (anchor != null) return anchor;
- var nodes = deepEqualsMap();
- var dartMap = setAnchor(map, new YamlMap.internal(nodes, map.span));
- super.visitMapping(map).forEach((k, v) => nodes[k] = v);
- return dartMap;
- }
-
- /// 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;
- var value = _anchors[anchored.anchor];
- if (value == 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.internal(value.nodes, anchored.span);
- } else if (value is YamlList) {
- return new YamlList.internal(value.nodes, anchored.span);
- } else {
- assert(value is YamlScalar);
- return new YamlScalar.internal(value.value, anchored.span);
- }
- }
-
- /// Records that [value] is the Dart object representing [anchored].
- 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/event.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698