From cace67f720786328ba94009195b85945244962db Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 30 Sep 2009 15:00:01 -0700 Subject: round tripping circular references --- lib/psych/visitors/to_ruby.rb | 5 ++++- lib/psych/visitors/yast_builder.rb | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3