parse_stream(yaml, filename = nil, &block)
Class Public methods
Parse a YAML string in yaml
. Returns the full AST for the
YAML document. This method can handle multiple YAML documents contained in
yaml
. filename
is used in the exception message
if a Psych::SyntaxError is raised.
If a block is given, a Psych::Nodes::Document node will be yielded to the block as it's being parsed.
Raises a Psych::SyntaxError when a YAML syntax error is detected.
Example:
Psych.parse_stream("---\n - a\n - b") # => #<Psych::Nodes::Stream:0x00> Psych.parse_stream("--- a\n--- b") do |node| node # => #<Psych::Nodes::Document:0x00> end begin Psych.parse_stream("--- `", "file.txt") rescue Psych::SyntaxError => ex ex.file # => 'file.txt' ex.message # => "(file.txt): found character that cannot start any token" end
See Psych::Nodes for more information about YAML AST.
Please login to continue.