summaryrefslogtreecommitdiff
path: root/ruby_2_2/ext/psych/lib/psych/parser.rb
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-14 15:09:35 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-14 15:09:35 +0000
commit1a74fa4b04da04bd2bb33103dd3cf431438df38e (patch)
treef4a1d6c2961339e0c1d653c0f8427a53315080f0 /ruby_2_2/ext/psych/lib/psych/parser.rb
parenta5b755e50e2d9aabf28ba24bf58644ca22b01a4f (diff)
add tag v2_2_9
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v2_2_9@61257 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_2_2/ext/psych/lib/psych/parser.rb')
-rw-r--r--ruby_2_2/ext/psych/lib/psych/parser.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/ruby_2_2/ext/psych/lib/psych/parser.rb b/ruby_2_2/ext/psych/lib/psych/parser.rb
new file mode 100644
index 0000000000..84085f1fb0
--- /dev/null
+++ b/ruby_2_2/ext/psych/lib/psych/parser.rb
@@ -0,0 +1,51 @@
+module Psych
+ ###
+ # YAML event parser class. This class parses a YAML document and calls
+ # events on the handler that is passed to the constructor. The events can
+ # be used for things such as constructing a YAML AST or deserializing YAML
+ # documents. It can even be fed back to Psych::Emitter to emit the same
+ # document that was parsed.
+ #
+ # See Psych::Handler for documentation on the events that Psych::Parser emits.
+ #
+ # Here is an example that prints out ever scalar found in a YAML document:
+ #
+ # # Handler for detecting scalar values
+ # class ScalarHandler < Psych::Handler
+ # def scalar value, anchor, tag, plain, quoted, style
+ # puts value
+ # end
+ # end
+ #
+ # parser = Psych::Parser.new(ScalarHandler.new)
+ # parser.parse(yaml_document)
+ #
+ # Here is an example that feeds the parser back in to Psych::Emitter. The
+ # YAML document is read from STDIN and written back out to STDERR:
+ #
+ # parser = Psych::Parser.new(Psych::Emitter.new($stderr))
+ # parser.parse($stdin)
+ #
+ # Psych uses Psych::Parser in combination with Psych::TreeBuilder to
+ # construct an AST of the parsed YAML document.
+
+ class Parser
+ class Mark < Struct.new(:index, :line, :column)
+ end
+
+ # The handler on which events will be called
+ attr_accessor :handler
+
+ # Set the encoding for this parser to +encoding+
+ attr_writer :external_encoding
+
+ ###
+ # Creates a new Psych::Parser instance with +handler+. YAML events will
+ # be called on +handler+. See Psych::Parser for more details.
+
+ def initialize handler = Handler.new
+ @handler = handler
+ @external_encoding = ANY
+ end
+ end
+end