1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/psych/lib/psych/parser.rb
tenderlove 0b38e9bc9d * ext/psych/lib/psych/parser.rb (Mark): Adding a class to wrap
marker information
* ext/psych/parser.c (mark): Add a method to return the mark object
  for the parser
* test/psych/test_parser.rb: tests for the Mark class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-17 19:44:31 +00:00

47 lines
1.5 KiB
Ruby

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
###
# 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
end
end
end