Skip to content

class YAML::PullParser
inherits Reference

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.

Class methods

.new(content : String | IO)

View source

.new

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

View source

Methods

#anchor

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

View source

#close

View source

#end_column

View source

#end_line

View source

#expect_kind(kind : EventKind)

Raises if the current kind is not the expected one.

View source

#finalize

View source

#kind : EventKind

The current event kind.

View source

#location

View source

#mapping_style : MappingStyle

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

View source

#raise(msg : String, line_number = self.start_line, column_number = self.start_column, context_info = nil)

View source

#read(expected_kind : EventKind) : EventKind

Reads an expected event kind.

View source

#read_alias

Reads an alias event, returning its anchor.

View source

#read_document

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

View source

#read_document_end

Reads a "document end" event.

View source

#read_document_start

Reads a "document start" event.

View source

#read_mapping

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

View source

#read_mapping_end

Reads a "mapping end" event.

View source

#read_mapping_start

Reads a "mapping start" event.

View source

#read_next : EventKind

Reads the next event.

View source

#read_scalar

Reads a scalar, returning its value.

View source

#read_sequence

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

View source

#read_sequence_end

Reads a "sequence end" event.

View source

#read_sequence_start

Reads a "sequence start" event.

View source

#read_stream

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

View source

#read_stream_end

Reads a "stream end" event.

View source

#read_stream_start

Reads a "stream start" event.

View source

#scalar_style : ScalarStyle

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

View source

#sequence_style : SequenceStyle

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

View source

#skip

View source

#start_column

View source

#start_line

View source

#tag : String?

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

View source

#value : String

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

View source