summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/psych.rb1
-rw-r--r--lib/psych/nodes/alias.rb15
-rw-r--r--lib/psych/tree_builder.rb6
-rw-r--r--test/psych/test_tree_builder.rb10
4 files changed, 31 insertions, 1 deletions
diff --git a/lib/psych.rb b/lib/psych.rb
index aaec4a7..df5486a 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -4,6 +4,7 @@ require 'psych/nodes/document'
require 'psych/nodes/sequence'
require 'psych/nodes/scalar'
require 'psych/nodes/mapping'
+require 'psych/nodes/alias'
require 'psych/handler'
require 'psych/tree_builder'
diff --git a/lib/psych/nodes/alias.rb b/lib/psych/nodes/alias.rb
new file mode 100644
index 0000000..b697cc1
--- /dev/null
+++ b/lib/psych/nodes/alias.rb
@@ -0,0 +1,15 @@
+module Psych
+ module Nodes
+ ###
+ # This class represents a {YAML Alias}[http://yaml.org/spec/1.1/#alias].
+ # It points to an +anchor+
+ class Alias < Psych::Nodes::Node
+ # The anchor this alias links to
+ attr_accessor :anchor
+
+ def initialize anchor
+ @anchor = anchor
+ end
+ end
+ end
+end
diff --git a/lib/psych/tree_builder.rb b/lib/psych/tree_builder.rb
index 6a10354..d9c7c5d 100644
--- a/lib/psych/tree_builder.rb
+++ b/lib/psych/tree_builder.rb
@@ -30,6 +30,7 @@ module Psych
end
def end_#{node.downcase}(*args)
+ super
@stack.pop
end
}
@@ -44,5 +45,10 @@ module Psych
super
@stack.last.children << Nodes::Scalar.new(*args)
end
+
+ def alias(*args)
+ super
+ @stack.last.children << Nodes::Alias.new(*args)
+ end
end
end
diff --git a/test/psych/test_tree_builder.rb b/test/psych/test_tree_builder.rb
index 0b51a10..552caed 100644
--- a/test/psych/test_tree_builder.rb
+++ b/test/psych/test_tree_builder.rb
@@ -12,7 +12,7 @@ module Psych
bar : &A !!str baz,
boo : *A
}
-- baz
+- *A
eoyml
@tree = @parser.handler.root
end
@@ -65,5 +65,13 @@ module Psych
assert_instance_of Nodes::Mapping, map
end
+
+ def test_alias
+ doc = @tree.children.first
+ seq = doc.children.first
+ al = seq.children[2]
+ assert_instance_of Nodes::Alias, al
+ assert_equal 'A', al.anchor
+ end
end
end