summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-27 20:12:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-27 20:12:53 -0700
commit4cb2ba04833af82a4618f2ebd03372bddc2047f5 (patch)
tree4d4906c077cf6ef9079035e609fe73acc1f14f3a /lib
parent9a8bfb1fe7a6c1443c31a0af36f30eb2f51d5515 (diff)
downloadpsych-4cb2ba04833af82a4618f2ebd03372bddc2047f5.zip
testing scalars
Diffstat (limited to 'lib')
-rw-r--r--lib/psych.rb2
-rw-r--r--lib/psych/nodes/mapping.rb15
-rw-r--r--lib/psych/nodes/scalar.rb35
-rw-r--r--lib/psych/tree_builder.rb32
4 files changed, 73 insertions, 11 deletions
diff --git a/lib/psych.rb b/lib/psych.rb
index 9c6397d..aaec4a7 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -2,6 +2,8 @@ require 'psych/nodes/node'
require 'psych/nodes/stream'
require 'psych/nodes/document'
require 'psych/nodes/sequence'
+require 'psych/nodes/scalar'
+require 'psych/nodes/mapping'
require 'psych/handler'
require 'psych/tree_builder'
diff --git a/lib/psych/nodes/mapping.rb b/lib/psych/nodes/mapping.rb
new file mode 100644
index 0000000..b1137e1
--- /dev/null
+++ b/lib/psych/nodes/mapping.rb
@@ -0,0 +1,15 @@
+module Psych
+ module Nodes
+ ###
+ # This class represents a {YAML Mapping}[http://yaml.org/spec/1.1/#mapping].
+ class Mapping < Psych::Nodes::Node
+ def initialize anchor, tag, implicit, style
+ super()
+ @anchor = anchor
+ @tag = tag
+ @implicit = implicit
+ @style = style
+ end
+ end
+ end
+end
diff --git a/lib/psych/nodes/scalar.rb b/lib/psych/nodes/scalar.rb
new file mode 100644
index 0000000..bfa494f
--- /dev/null
+++ b/lib/psych/nodes/scalar.rb
@@ -0,0 +1,35 @@
+module Psych
+ module Nodes
+ ###
+ # This class represents a {YAML Scalar}[http://yaml.org/spec/1.1/#id858081].
+ class Scalar < Psych::Nodes::Node
+ # The scalar value
+ attr_accessor :value
+
+ # The anchor value (if there is one)
+ attr_accessor :anchor
+
+ # The tag value (if there is one)
+ attr_accessor :tag
+
+ # Is this a plain scalar?
+ attr_accessor :plain
+
+ # Is this scalar quoted?
+ attr_accessor :quoted
+
+ # The style of this scalar
+ attr_accessor :style
+
+ def initialize value, anchor, tag, plain, quoted, style
+ super()
+ @value = value
+ @anchor = anchor
+ @tag = tag
+ @plain = plain
+ @quoted = quoted
+ @style = style
+ end
+ end
+ end
+end
diff --git a/lib/psych/tree_builder.rb b/lib/psych/tree_builder.rb
index c7e46fb..6a10354 100644
--- a/lib/psych/tree_builder.rb
+++ b/lib/psych/tree_builder.rb
@@ -16,23 +16,33 @@ module Psych
@stack.first
end
- def start_stream encoding
- super
- @stack.push Nodes::Stream.new encoding
+ %w{
+ Document
+ Sequence
+ Mapping
+ }.each do |node|
+ class_eval %{
+ def start_#{node.downcase}(*args)
+ super
+ n = Nodes::#{node}.new(*args)
+ @stack.last.children << n
+ @stack.push n
+ end
+
+ def end_#{node.downcase}(*args)
+ @stack.pop
+ end
+ }
end
- def start_document version = [], tag_directives = [], implicit = true
+ def start_stream encoding
super
- doc = Nodes::Document.new version, tag_directives, implicit
- @stack.last.children << doc
- @stack.push doc
+ @stack.push Nodes::Stream.new encoding
end
- def start_sequence anchor = nil, tag = nil, implicit = true, style = BLOCK_SEQUENCE_STYLE
+ def scalar(*args)
super
- seq = Nodes::Sequence.new anchor, tag, implicit, style
- @stack.last.children << seq
- @stack.push seq
+ @stack.last.children << Nodes::Scalar.new(*args)
end
end
end