summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-02-20 14:29:13 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-02-20 14:29:13 -0800
commitc0ea6504cc7b1000c11babadf9e233e1b18291f8 (patch)
tree6a467f9f6a94e78f33904bc9aeb541fa89682eaa /lib
parent62109d4ecb1650ee86e15e5d15df5692206390dc (diff)
downloadpsych-c0ea6504cc7b1000c11babadf9e233e1b18291f8.zip
yaml as sequence is working
Diffstat (limited to 'lib')
-rw-r--r--lib/psych/coder.rb6
-rw-r--r--lib/psych/visitors/to_ruby.rb12
-rw-r--r--lib/psych/visitors/yaml_tree.rb6
3 files changed, 24 insertions, 0 deletions
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