OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library yaml.constructor; | 5 library yaml.constructor; |
6 | 6 |
7 import 'equality.dart'; | 7 import 'equality.dart'; |
8 import 'model.dart'; | 8 import 'model.dart'; |
9 import 'visitor.dart'; | 9 import 'visitor.dart'; |
10 import 'yaml_node.dart'; | 10 import 'yaml_node.dart'; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 var dartMap = setAnchor(map, new YamlMap(nodes, map.span)); | 46 var dartMap = setAnchor(map, new YamlMap(nodes, map.span)); |
47 super.visitMapping(map).forEach((k, v) => nodes[k] = v); | 47 super.visitMapping(map).forEach((k, v) => nodes[k] = v); |
48 return dartMap; | 48 return dartMap; |
49 } | 49 } |
50 | 50 |
51 /// Returns a new Dart object wrapping the object that already represents | 51 /// Returns a new Dart object wrapping the object that already represents |
52 /// [anchored], if such a thing exists. | 52 /// [anchored], if such a thing exists. |
53 YamlNode getAnchor(Node anchored) { | 53 YamlNode getAnchor(Node anchored) { |
54 if (anchored.anchor == null) return null; | 54 if (anchored.anchor == null) return null; |
55 var value = _anchors[anchored.anchor]; | 55 var value = _anchors[anchored.anchor]; |
56 if (vaule == null) return null; | 56 if (value == null) return null; |
57 | 57 |
58 // Re-wrap [value]'s contents so that it's associated with the span of the | 58 // Re-wrap [value]'s contents so that it's associated with the span of the |
59 // anchor rather than its original definition. | 59 // anchor rather than its original definition. |
60 if (value is YamlMap) return new YamlMap(value.nodes, anchored.span); | 60 if (value is YamlMap) return new YamlMap(value.nodes, anchored.span); |
61 if (value is YamlList) return new YamlList(value.nodes, anchored.span); | 61 if (value is YamlList) return new YamlList(value.nodes, anchored.span); |
62 assert(value is YamlScalar); | 62 assert(value is YamlScalar); |
63 return new YamlScalar(value.value, anchored.span); | 63 return new YamlScalar(value.value, anchored.span); |
64 } | 64 } |
65 | 65 |
66 /// Records that [value] is the Dart object representing [anchored]. | 66 /// Records that [value] is the Dart object representing [anchored]. |
67 YamlNode setAnchor(Node anchored, YamlNode value) { | 67 YamlNode setAnchor(Node anchored, YamlNode value) { |
68 if (anchored.anchor == null) return value; | 68 if (anchored.anchor == null) return value; |
69 _anchors[anchored.anchor] = value; | 69 _anchors[anchored.anchor] = value; |
70 return value; | 70 return value; |
71 } | 71 } |
72 } | 72 } |
OLD | NEW |