diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-16 23:50:23 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-16 23:50:23 +0000 |
commit | 2f3998851148a1b95f9f4e5b6ccf48a9400c33cc (patch) | |
tree | b05147ef9dce4df0ac44e84cd59f7ef3b11594da /ext/psych/lib/psych/tree_builder.rb | |
parent | d62a9f00b87a378cdf1f52fe63e9bcfde62a853b (diff) |
* ext/psych/lib/psych/emitter.rb: removing unused file.
* ext/psych/lib/psych/json/tree_builder.rb: moving tree builder to an
event based external class.
* ext/psych/lib/psych/tree_builder.rb: adding an end_stream event.
* ext/psych/lib/psych/visitors/json_tree.rb: using event based AST
builder.
* ext/psych/lib/psych/visitors/yaml_tree.rb: using event based AST
builder.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych/tree_builder.rb')
-rw-r--r-- | ext/psych/lib/psych/tree_builder.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/ext/psych/lib/psych/tree_builder.rb b/ext/psych/lib/psych/tree_builder.rb index 2b16290b8f..54d87a0b61 100644 --- a/ext/psych/lib/psych/tree_builder.rb +++ b/ext/psych/lib/psych/tree_builder.rb @@ -14,15 +14,14 @@ module Psych # See Psych::Handler for documentation on the event methods used in this # class. class TreeBuilder < Psych::Handler + # Returns the root node for the built tree + attr_reader :root + # Create a new TreeBuilder instance def initialize @stack = [] @last = nil - end - - # Returns the root node for the built tree - def root - @stack.first + @root = nil end %w{ @@ -48,7 +47,7 @@ module Psych # # See Psych::Handler#start_document def start_document version, tag_directives, implicit - n = Nodes::Document.new(version, tag_directives, implicit) + n = Nodes::Document.new version, tag_directives, implicit @last.children << n push n end @@ -64,7 +63,12 @@ module Psych end def start_stream encoding - push Nodes::Stream.new(encoding) + @root = Nodes::Stream.new(encoding) + push @root + end + + def end_stream + pop end def scalar value, anchor, tag, plain, quoted, style @@ -82,8 +86,9 @@ module Psych end def pop - @stack.pop + x = @stack.pop @last = @stack.last + x end end end |