summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-12-16 17:49:07 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2009-12-16 17:49:07 -0800
commit9843d25b096edfbf9fe5ab29a15c2447158c925d (patch)
treec198f30e692da5c076473098318f084e3da1adaa /lib
parent8eb94e153ce730c88aebb95595a7f9f7b7f5e0f8 (diff)
downloadpsych-9843d25b096edfbf9fe5ab29a15c2447158c925d.zip
adding the set implementation
Diffstat (limited to 'lib')
-rw-r--r--lib/psych.rb1
-rw-r--r--lib/psych/set.rb4
-rw-r--r--lib/psych/visitors/to_ruby.rb3
-rw-r--r--lib/psych/visitors/yaml_tree.rb14
4 files changed, 22 insertions, 0 deletions
diff --git a/lib/psych.rb b/lib/psych.rb
index 9b9a079..4327637 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -15,6 +15,7 @@ require 'psych/tree_builder'
require 'psych/parser'
require 'psych/ruby'
require 'psych/omap'
+require 'psych/set'
require 'psych/psych'
module Psych
diff --git a/lib/psych/set.rb b/lib/psych/set.rb
new file mode 100644
index 0000000..6793a8e
--- /dev/null
+++ b/lib/psych/set.rb
@@ -0,0 +1,4 @@
+module Psych
+ class Set < ::Hash
+ end
+end
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index dbe4a39..31a7018 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -124,6 +124,9 @@ module Psych
h.each { |k,v| e.instance_variable_set :"@#{k}", v }
e
+ when '!set', 'tag:yaml.org,2002:set'
+ Psych::Set[*o.children.map { |c| accept c }]
+
when '!ruby/object:Complex'
h = Hash[*o.children.map { |c| accept c }]
Complex(h['real'], h['image'])
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index ba0307b..ee5fb74 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -20,6 +20,20 @@ module Psych
raise TypeError, "Can't dump #{target.class}"
end
+ def visit_Psych_Set o
+ map = Nodes::Mapping.new(nil, '!set', false)
+ @st[o.object_id] = map
+
+ @stack.push append map
+
+ o.each do |k,v|
+ accept k
+ accept v
+ end
+
+ @stack.pop
+ end
+
def visit_Psych_Omap o
@stack.push append Nodes::Sequence.new(nil, '!omap', false)
o.each do |k,v|