diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-27 18:40:33 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-27 18:40:33 -0700 |
commit | 6f404ba338038732d8f3ebbb02b977d1ab42e0a1 (patch) | |
tree | b09b439bb9d3bbb219288dd94ae9d170d025aff2 /lib | |
parent | 7d3bb196d32afb5f9fe7ec54eb7f7f1c6fb41a86 (diff) | |
download | psych-6f404ba338038732d8f3ebbb02b977d1ab42e0a1.zip |
addign document and stream nodes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych.rb | 5 | ||||
-rw-r--r-- | lib/psych/nodes/document.rb | 12 | ||||
-rw-r--r-- | lib/psych/nodes/node.rb | 14 | ||||
-rw-r--r-- | lib/psych/nodes/stream.rb | 14 | ||||
-rw-r--r-- | lib/psych/tree_builder.rb | 29 |
5 files changed, 74 insertions, 0 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index 9d136d5..d39a284 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -1,4 +1,9 @@ +require 'psych/nodes/node' +require 'psych/nodes/stream' +require 'psych/nodes/document' + require 'psych/handler' +require 'psych/tree_builder' require 'psych/parser' require 'psych/psych' diff --git a/lib/psych/nodes/document.rb b/lib/psych/nodes/document.rb new file mode 100644 index 0000000..8dc0a13 --- /dev/null +++ b/lib/psych/nodes/document.rb @@ -0,0 +1,12 @@ +module Psych + module Nodes + class Document < Psych::Nodes::Node + def initialize version, tag_directives, implicit + super() + @version = version + @tag_directives = tag_directives + @implicit = implicit + end + end + end +end diff --git a/lib/psych/nodes/node.rb b/lib/psych/nodes/node.rb new file mode 100644 index 0000000..cb8f632 --- /dev/null +++ b/lib/psych/nodes/node.rb @@ -0,0 +1,14 @@ +module Psych + module Nodes + ### + # The base class for any Node in a YAML parse tree. This class should + # never be instantiated. + class Node + attr_reader :children + + def initialize + @children = [] + end + end + end +end diff --git a/lib/psych/nodes/stream.rb b/lib/psych/nodes/stream.rb new file mode 100644 index 0000000..911bea8 --- /dev/null +++ b/lib/psych/nodes/stream.rb @@ -0,0 +1,14 @@ +module Psych + module Nodes + ### + # Represents a YAML stream. This is the root node for any YAML parse + # tree. + class Stream < Psych::Nodes::Node + attr_reader :encoding + def initialize encoding + super() + @encoding = encoding + end + end + end +end diff --git a/lib/psych/tree_builder.rb b/lib/psych/tree_builder.rb new file mode 100644 index 0000000..3f11fd9 --- /dev/null +++ b/lib/psych/tree_builder.rb @@ -0,0 +1,29 @@ +require 'psych/handler' + +module Psych + ### + # This class builds an in-memory parse tree tree that represents a YAML + # document. + # + # See Psych::Handler for documentation on the event methods used in this + # class. + class TreeBuilder < Psych::Handler + def initialize + @stack = [] + end + + def root + @stack.first + end + + def start_stream encoding + @stack.push Nodes::Stream.new encoding + end + + def start_document version = [], tag_directives = [], implicit = true + doc = Nodes::Document.new version, tag_directives, implicit + @stack.last.children << doc + @stack.push doc + end + end +end |