diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-12-17 09:22:52 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-12-17 09:22:52 -0800 |
commit | 31126b53bbe0d88f0c1050f81ce88f847c13b5d3 (patch) | |
tree | df1538e010876f18c1619d7e6591e06b48f32fcb /lib | |
parent | f0ec58031ed3f4ae9f18830151556cfe26a9b80a (diff) | |
download | psych-31126b53bbe0d88f0c1050f81ce88f847c13b5d3.zip |
dealing with self referential omaps
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 1 | ||||
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 10 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 15e7d06..aed56ed 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -72,6 +72,7 @@ module Psych case o.tag when '!omap', 'tag:yaml.org,2002:omap' map = Psych::Omap.new + @st[o.anchor] = map if o.anchor o.children.each { |a| map[accept(a.children.first)] = accept a.children.last } diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 60d54ad..995a890 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -40,7 +40,15 @@ module Psych end def visit_Psych_Omap o - @stack.push append Nodes::Sequence.new(nil, '!omap', false) + if node = @st[o.object_id] + node.anchor = o.object_id.to_s + return append Nodes::Alias.new o.object_id.to_s + end + + seq = Nodes::Sequence.new(nil, '!omap', false) + @st[o.object_id] = seq + + @stack.push append seq o.each do |k,v| accept k => v end |