# class YAML::PullParser

- YAML::PullParser
- Reference
- Object

##
Overview

A pull parser allows parsing a YAML document by events.

When creating an instance, the parser is positioned in the first event. To get the event kind invoke `#kind`. If the event is a scalar you can invoke `#value` to get its string value. Other methods like `#tag`, `#anchor` and `#scalar_style` let you inspect other information from events.

Invoking `#read_next` reads the next event.

##
Defined in:

yaml/pull_parser.cr

##
Constructors

- .new(content : String | IO)
- .new(content, &)

  Creates a parser, yields it to the block, and closes the parser at the end of it.

##
Instance Method Summary

- #anchor : String | Nil

  Returns the anchor associated to the current event, or `nil` if there's no anchor.

- #close : Nil
- #end_column : Int32
- #end_line : Int32
- #expect_kind(kind : EventKind) : Nil

  Raises if the current kind is not the expected one.

- #finalize
- #kind : EventKind

  The current event kind.

- #location : Tuple(Int32, Int32)
- #mapping_style : MappingStyle

  Returns the mapping style, assuming the pull parser is located at a mapping begin event.

- #raise(msg : String, line_number = self.start_line, column_number = self.start_column, context_info = nil) : NoReturn
- #read(expected_kind : EventKind) : EventKind

  Reads an expected event kind.

- #read_alias : String | Nil

  Reads an alias event, returning its anchor.

- #read_document(&)

  Reads a "document start" event, yields to the block, and then reads a "document end" event.

- #read_document_end

  Reads a "document end" event.

- #read_document_start

  Reads a "document start" event.

- #read_mapping(&)

  Reads a "mapping start" event, yields to the block, and then reads a "mapping end" event.

- #read_mapping_end

  Reads a "mapping end" event.

- #read_mapping_start

  Reads a "mapping start" event.

- #read_next : EventKind

  Reads the next event.

- #read_scalar : String

  Reads a scalar, returning its value.

- #read_sequence(&)

  Reads a "sequence start" event, yields to the block, and then reads a "sequence end" event.

- #read_sequence_end

  Reads a "sequence end" event.

- #read_sequence_start

  Reads a "sequence start" event.

- #read_stream(&)

  Reads a "stream start" event, yields to the block, and then reads a "stream end" event.

- #read_stream_end

  Reads a "stream end" event.

- #read_stream_start

  Reads a "stream start" event.

- #scalar_style : ScalarStyle

  Returns the scalar style, assuming the pull parser is located at a scalar event.

- #sequence_style : SequenceStyle

  Returns the sequence style, assuming the pull parser is located at a sequence begin event.

- #skip : YAML::EventKind
- #start_column : Int32
- #start_line : Int32
- #tag : String | Nil

  Returns the tag associated to the current event, or `nil` if there's no tag.

- #value : String

  Returns the scalar value, assuming the pull parser is located at a scalar.

### Instance methods inherited from class `Reference`

==(other : self)
==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup, hash(hasher) hash, initialize initialize, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference) : Bool
same?(other : Nil) same?, to_s(io : IO) : Nil to_s

### Constructor methods inherited from class `Reference`

new new, unsafe_construct(address : Pointer, *args, **opts) : self unsafe_construct

### Class methods inherited from class `Reference`

pre_initialize(address : Pointer) pre_initialize

### Instance methods inherited from class `Object`

! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as

### Class methods inherited from class `Object`

from_json(string_or_io, root : String)
from_json(string_or_io) from_json, from_yaml(string_or_io : String | IO) from_yaml

### Macros inherited from class `Object`

class_getter(*names, &block) class_getter, class_getter!(*names) class_getter!, class_getter?(*names, &block) class_getter?, class_property(*names, &block) class_property, class_property!(*names) class_property!, class_property?(*names, &block) class_property?, class_setter(*names) class_setter, def_clone def_clone, def_equals(*fields) def_equals, def_equals_and_hash(*fields) def_equals_and_hash, def_hash(*fields) def_hash, delegate(*methods, to object) delegate, forward_missing_to(delegate) forward_missing_to, getter(*names, &block) getter, getter!(*names) getter!, getter?(*names, &block) getter?, property(*names, &block) property, property!(*names) property!, property?(*names, &block) property?, setter(*names) setter

##
Constructor Detail

def self.new(content : String | IO) #
def self.new(content, &) #

Creates a parser, yields it to the block, and closes the parser at the end of it.

##
Instance Method Detail

def anchor : String | Nil #

Returns the anchor associated to the current event, or `nil` if there's no anchor.

def close : Nil #
def end_column : Int32 #
def end_line : Int32 #
def expect_kind(kind : EventKind) : Nil #

Raises if the current kind is not the expected one.

def finalize #
def kind : EventKind #

The current event kind.

def location : Tuple(Int32, Int32) #
def mapping_style : MappingStyle #

Returns the mapping style, assuming the pull parser is located at a mapping begin event. Raises otherwise.

def raise(msg : String, line_number = self.start_line, column_number = self.start_column, context_info = nil) : NoReturn #
def read(expected_kind : EventKind) : EventKind #

Reads an expected event kind.

def read_alias : String | Nil #

Reads an alias event, returning its anchor.

def read_document(&) #

Reads a "document start" event, yields to the block, and then reads a "document end" event.

def read_document_end #

Reads a "document end" event.

def read_document_start #

Reads a "document start" event.

def read_mapping(&) #

Reads a "mapping start" event, yields to the block, and then reads a "mapping end" event.

def read_mapping_end #

Reads a "mapping end" event.

def read_mapping_start #

Reads a "mapping start" event.

def read_next : EventKind #

Reads the next event.

def read_scalar : String #

Reads a scalar, returning its value.

def read_sequence(&) #

Reads a "sequence start" event, yields to the block, and then reads a "sequence end" event.

def read_sequence_end #

Reads a "sequence end" event.

def read_sequence_start #

Reads a "sequence start" event.

def read_stream(&) #

Reads a "stream start" event, yields to the block, and then reads a "stream end" event.

def read_stream_end #

Reads a "stream end" event.

def read_stream_start #

Reads a "stream start" event.

def scalar_style : ScalarStyle #

Returns the scalar style, assuming the pull parser is located at a scalar event. Raises otherwise.

def sequence_style : SequenceStyle #

Returns the sequence style, assuming the pull parser is located at a sequence begin event. Raises otherwise.

def skip : YAML::EventKind #
def start_column : Int32 #
def start_line : Int32 #
def tag : String | Nil #

Returns the tag associated to the current event, or `nil` if there's no tag.

def value : String #

Returns the scalar value, assuming the pull parser is located at a scalar. Raises otherwise.