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 part of yaml; | 5 library visitor; |
| 6 |
| 7 import 'model.dart'; |
| 8 import 'yaml_map.dart'; |
6 | 9 |
7 /// The visitor pattern for YAML documents. | 10 /// The visitor pattern for YAML documents. |
8 class _Visitor { | 11 class Visitor { |
9 /// Returns [alias]. | 12 /// Returns [alias]. |
10 visitAlias(_AliasNode alias) => alias; | 13 visitAlias(AliasNode alias) => alias; |
11 | 14 |
12 /// Returns [scalar]. | 15 /// Returns [scalar]. |
13 visitScalar(_ScalarNode scalar) => scalar; | 16 visitScalar(ScalarNode scalar) => scalar; |
14 | 17 |
15 /// Visits each node in [seq] and returns a list of the results. | 18 /// Visits each node in [seq] and returns a list of the results. |
16 visitSequence(_SequenceNode seq) | 19 visitSequence(SequenceNode seq) |
17 => seq.content.map((e) => e.visit(this)).toList(); | 20 => seq.content.map((e) => e.visit(this)).toList(); |
18 | 21 |
19 /// Visits each key and value in [map] and returns a map of the results. | 22 /// Visits each key and value in [map] and returns a map of the results. |
20 visitMapping(_MappingNode map) { | 23 visitMapping(MappingNode map) { |
21 var out = new YamlMap(); | 24 var out = new YamlMap(); |
22 for (var key in map.content.keys) { | 25 for (var key in map.content.keys) { |
23 out[key.visit(this)] = map.content[key].visit(this); | 26 out[key.visit(this)] = map.content[key].visit(this); |
24 } | 27 } |
25 return out; | 28 return out; |
26 } | 29 } |
27 } | 30 } |
OLD | NEW |