diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-01-17 13:49:56 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-01-17 13:49:56 -0800 |
commit | 7cb15116f5702c729abdc9888120704e5a828e27 (patch) | |
tree | 847247785180f41fdfbcf394079576d73331e037 /lib/psych/tree_builder.rb | |
parent | e57fa551ebc9651251e156d6532ab290bbc92e04 (diff) | |
download | psych-7cb15116f5702c729abdc9888120704e5a828e27.tar.gz |
more documentation!
Diffstat (limited to 'lib/psych/tree_builder.rb')
-rw-r--r-- | lib/psych/tree_builder.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/psych/tree_builder.rb b/lib/psych/tree_builder.rb index db0a637..6437a73 100644 --- a/lib/psych/tree_builder.rb +++ b/lib/psych/tree_builder.rb @@ -2,17 +2,25 @@ require 'psych/handler' module Psych ### - # This class builds an in-memory parse tree tree that represents a YAML - # document. + # This class works in conjunction with Psych::Parser to build an in-memory + # parse tree tree that represents a YAML document. + # + # == Example + # + # parser = Psych::Parser.new Psych::TreeBuilder.new + # parser.parse('--- foo') + # tree = parser.handler.root # # See Psych::Handler for documentation on the event methods used in this # class. class TreeBuilder < Psych::Handler + # Create a new TreeBuilder instance def initialize @stack = [] @last = nil end + # Returns the root node for the built tree def root @stack.first end @@ -34,12 +42,22 @@ module Psych } end + ### + # Handles start_document events with +version+, +tag_directives+, + # and +implicit+ styling. + # + # See Psych::Handler#start_document def start_document version, tag_directives, implicit n = Nodes::Document.new(version, tag_directives, implicit) @last.children << n push n end + ### + # Handles end_document events with +version+, +tag_directives+, + # and +implicit+ styling. + # + # See Psych::Handler#start_document def end_document implicit_end @last.implicit_end = implicit_end pop |