parser

package
v0.0.0-...-ec9fd1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2012 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Overview

The parser package takes a sequence of tokens and transforms it into a representation graph (and optionally into native data structures). This corresponds to the composing and constructing stages in the YAML 1.2 specification.

Index

Constants

View Source
const DefaultPrefix = "tag:yaml.org,2002:"

Variables

This section is empty.

Functions

This section is empty.

Types

type Constructor

type Constructor interface {
	Construct(node Node, userData interface{}) (data interface{}, err error)
}

A Constructor converts a Node into a Go data structure.

type Document

type Document struct {
	MajorVersion int
	MinorVersion int
	Content      Node
}

Document stores data related to a single document in a stream.

type Empty

type Empty struct {
	// contains filtered or unexported fields
}

An Empty indicates a lack of a value.

func (Empty) Data

func (n Empty) Data() interface{}

func (Empty) Start

func (n Empty) Start() token.Position

func (Empty) Tag

func (n Empty) Tag() string

type Error

type Error struct {
	Err  error
	Node Node
}

An Error is a high-level parser error, including the node.

func (Error) Error

func (err Error) Error() string

type KeyValuePair

type KeyValuePair struct {
	Key, Value Node
}

A KeyValuePair stores a single pair in a mapping.

type Mapping

type Mapping struct {
	Pairs []KeyValuePair
	// contains filtered or unexported fields
}

Mapping stores a key-value mapping of nodes.

func (Mapping) Data

func (n Mapping) Data() interface{}

func (*Mapping) Get

func (m *Mapping) Get(key string) (value Node, ok bool)

Get returns the value for a scalar that has the same content as key.

func (*Mapping) Len

func (m *Mapping) Len() int

Len returns the number of pairs in the mapping.

func (*Mapping) Map

func (node *Mapping) Map() (m map[interface{}]interface{})

Map returns the content of the mapping as a native Go map.

func (Mapping) Start

func (n Mapping) Start() token.Position

func (Mapping) Tag

func (n Mapping) Tag() string

type Node

type Node interface {
	Start() token.Position
	Tag() string
	Data() interface{}
	// contains filtered or unexported methods
}

Node defines a node of the representation graph.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

A Parser transforms a YAML stream into data structures.

func New

func New(r io.Reader, s Schema, c Constructor, userData interface{}) *Parser

New creates a new parser that reads from the given reader.

func NewWithScanner

func NewWithScanner(scan *scanner.Scanner, schema Schema, con Constructor, userData interface{}) (p *Parser)

NewWithScanner creates a new parser that reads from an existing scanner.

func (*Parser) Parse

func (parser *Parser) Parse() (docs []*Document, err error)

Parse returns all of the documents in the stream.

func (*Parser) ParseDocument

func (parser *Parser) ParseDocument() (doc *Document, err error)

ParseDocument returns the next document in the stream.

type Scalar

type Scalar struct {
	Value string
	// contains filtered or unexported fields
}

Scalar stores a text value.

func (Scalar) Data

func (n Scalar) Data() interface{}

func (Scalar) Start

func (n Scalar) Start() token.Position

func (*Scalar) String

func (s *Scalar) String() string

String returns the original string that was used to construct the value.

func (Scalar) Tag

func (n Scalar) Tag() string

type Schema

type Schema interface {
	Resolve(node Node, userData interface{}) (tag string, err error)
}

A Schema determines the tag for a node without an explicit tag.

type Sequence

type Sequence struct {
	Nodes []Node
	// contains filtered or unexported fields
}

Sequence stores an ordered collection of nodes.

func (*Sequence) At

func (seq *Sequence) At(i int) Node

At returns the node at the given index.

func (Sequence) Data

func (n Sequence) Data() interface{}

func (*Sequence) Len

func (seq *Sequence) Len() int

Len returns the number of nodes in the sequence.

func (*Sequence) Slice

func (seq *Sequence) Slice() (s []interface{})

Slice returns the content of the sequence as a native Go slice.

func (Sequence) Start

func (n Sequence) Start() token.Position

func (Sequence) Tag

func (n Sequence) Tag() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL