From c0ea6504cc7b1000c11babadf9e233e1b18291f8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 20 Feb 2010 14:29:13 -0800 Subject: yaml as sequence is working --- lib/psych/coder.rb | 6 ++++++ lib/psych/visitors/to_ruby.rb | 12 ++++++++++++ lib/psych/visitors/yaml_tree.rb | 6 ++++++ 3 files changed, 24 insertions(+) (limited to 'lib') diff --git a/lib/psych/coder.rb b/lib/psych/coder.rb index fe3dab2..ae88e4a 100644 --- a/lib/psych/coder.rb +++ b/lib/psych/coder.rb @@ -25,6 +25,12 @@ module Psych self.scalar = value end + # Emit a sequence with +value+ and +tag+ + def represent_seq tag, list + @tag = tag + self.seq = list + end + # Emit a scalar with +value+ def scalar= value @type = :scalar diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index a66b2e6..d5704bb 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -80,6 +80,18 @@ module Psych end def visit_Psych_Nodes_Sequence o + if klass = Psych.load_tags[o.tag] + instance = klass.allocate + + if instance.respond_to?(:init_with) + coder = Psych::Coder.new(o.tag) + coder.seq = o.children.map { |c| accept c } + instance.init_with coder + end + + return instance + end + case o.tag when '!omap', 'tag:yaml.org,2002:omap' map = Psych::Omap.new diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 3ea7685..06e1862 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -257,6 +257,12 @@ module Psych case c.type when :scalar append create_scalar(c.scalar, nil, c.tag, c.tag.nil?) + when :seq + @stack.push append create_sequence(nil, c.tag, c.tag.nil?) + c.seq.each do |thing| + accept thing + end + @stack.pop when :map map = append Nodes::Mapping.new(nil, c.tag, c.implicit, c.style) @stack.push map -- cgit v1.2.3