diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 15:00:01 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 15:00:01 -0700 |
commit | cace67f720786328ba94009195b85945244962db (patch) | |
tree | 3db684052e76c64fe1955c61ed423b8b9e96e4a6 /lib | |
parent | 0fdc41a6e3ab790e58db0e0f54affe5d2a8277f2 (diff) | |
download | psych-cace67f720786328ba94009195b85945244962db.zip |
round tripping circular references
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 5 | ||||
-rw-r--r-- | lib/psych/visitors/yast_builder.rb | 11 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 84813ed..836c0b6 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -19,7 +19,10 @@ module Psych end def visit_Psych_Nodes_Sequence o - o.children.map { |c| c.accept self } + list = [] + @st[o.anchor] = list if o.anchor + o.children.each { |c| list.push c.accept self } + list end def visit_Psych_Nodes_Mapping o diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb index 5de56ae..5dd7dc5 100644 --- a/lib/psych/visitors/yast_builder.rb +++ b/lib/psych/visitors/yast_builder.rb @@ -8,6 +8,7 @@ module Psych @tree = Nodes::Stream.new @tree.children << Nodes::Document.new @stack = @tree.children.dup + @st = {} end def accept target @@ -57,7 +58,15 @@ module Psych end def visit_Array o - @stack.push append Nodes::Sequence.new + 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 + @st[o.object_id] = seq + + @stack.push append seq o.each { |c| c.accept self } @stack.pop end |