parser

package
v0.0.0-...-70fd0a4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package parser contains functions and types to parse tokens into YAML AST.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(cts ConfigurableTokenStream) (ast.Node, error)

Parse builds an YAML AST using tokens from given token stream.

func ParseBytes

func ParseBytes(src []byte, opts ...ParseOption) (ast.Node, error)

ParseBytes builds an YAML AST from parsing provided bytes slice.

func ParseString

func ParseString(src string, opts ...ParseOption) (ast.Node, error)

ParseString builds an YAML AST from parsing provided source string.

func ParseTokenStream

func ParseTokenStream(cts ConfigurableTokenStream) (ast.Node, error)

ParseTokenStream builds an YAML AST using tokens from given token stream.

func ParseTokens

func ParseTokens(tokens []token.Token) (ast.Node, error)

ParseTokens builds an YAML AST using provided tokens.

Types

type ConfigurableTokenStream

type ConfigurableTokenStream interface {
	cpaccessor.ResourceStream[token.Token]
	RawTokenModer
}

ConfigurableTokenStream represents a token stream with abilities to set checkpoints and change mode to raw tokens.

type DeadEndError

type DeadEndError struct {
	Pos token.Position
}

DeadEndError is used to indicate some sort of loops occured during parsing when the same token appears multiple times. When YAML document is correct, there will be no 'dead ends' because parsing will go lightly.

func (DeadEndError) Error

func (d DeadEndError) Error() string

type ParseOption

type ParseOption interface {
	// contains filtered or unexported methods
}

ParseOption allows to modify parser behavior

func WithOmitStream

func WithOmitStream() ParseOption

WithOmitStream will make parser to omit stream node from AST in case the stream has only one document.

func WithTokenStreamConstructor

func WithTokenStreamConstructor(tsConstructor func(string) ConfigurableTokenStream) ParseOption

WithTokenStreamConstructor will make parser use the token stream constructed with given constructor function.

type RawTokenModer

type RawTokenModer interface {
	SetRawMode()
	UnsetRawMode()
}

RawTokenModer is used to set "raw mode" in lexer, meaning it almost will not change it's state from incoming tokens.

type TagError

type TagError struct {
	Src string
	Pos token.Position
}

TagError indicates case when tag has a string after it which is not allowed in YAML.

func (TagError) Error

func (t TagError) Error() string

type UnbalancedClosingParenthesisError

type UnbalancedClosingParenthesisError struct {
	Tok token.Token
}

UnbalancedClosingParenthesisError is used to indicate case when a closing parenthesis (or bracket) appears in source without corresponding opening counterpart. E.g. "[]]"

func (UnbalancedClosingParenthesisError) Error

type UnbalancedOpeningParenthesisError

type UnbalancedOpeningParenthesisError struct {
	ExpectedPos token.Position
	// contains filtered or unexported fields
}

UnbalancedOpeningParenthesisError is used to indicate case when an opening parenthesis (or bracket) appears in source without corresponding closing counterpart. E.g. "[[]"

func (UnbalancedOpeningParenthesisError) Error

type UnbalancedQuotesError

type UnbalancedQuotesError struct {
	ExpectedPos token.Position
	// contains filtered or unexported fields
}

UnbalancedQuotesError is used to indicate case when an opening quote appears in source without corresponding closing counterpart. E.g. `'` or `"text" "`

func (UnbalancedQuotesError) Error

func (u UnbalancedQuotesError) Error() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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