Psych::Parser - ri - phpman

Look up a command

 

Markdown Format | JSON API | MCP Server Tool


= Psych::Parser < Object

(from gem psych-5.4.0)
------------------------------------------------------------------------

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.
------------------------------------------------------------------------
= Constants:

ANY:
  Let the parser choose the encoding


UTF16BE:
  UTF-16-BE Encoding with BOM


UTF16LE:
  UTF-16-LE Encoding with BOM


UTF8:
  UTF-8 Encoding



= Class methods:

  new

= Instance methods:

  _native_parse
  external_encoding
  handler
  mark
  parse

= Attributes:

  attr_accessor handler
  attr_writer external_encoding


Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:16 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 TransitionalValid CSS!