token

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 2 Imported by: 30

Documentation

Index

Constants

View Source
const (
	// SequenceEntryCharacter character for sequence entry
	SequenceEntryCharacter Character = '-'
	// MappingKeyCharacter character for mapping key
	MappingKeyCharacter = '?'
	// MappingValueCharacter character for mapping value
	MappingValueCharacter = ':'
	// CollectEntryCharacter character for collect entry
	CollectEntryCharacter = ','
	// SequenceStartCharacter character for sequence start
	SequenceStartCharacter = '['
	// SequenceEndCharacter character for sequence end
	SequenceEndCharacter = ']'
	// MappingStartCharacter character for mapping start
	MappingStartCharacter = '{'
	// MappingEndCharacter character for mapping end
	MappingEndCharacter = '}'
	// CommentCharacter character for comment
	CommentCharacter = '#'
	// AnchorCharacter character for anchor
	AnchorCharacter = '&'
	// AliasCharacter character for alias
	AliasCharacter = '*'
	// TagCharacter character for tag
	TagCharacter = '!'
	// LiteralCharacter character for literal
	LiteralCharacter = '|'
	// FoldedCharacter character for folded
	FoldedCharacter = '>'
	// SingleQuoteCharacter character for single quote
	SingleQuoteCharacter = '\''
	// DoubleQuoteCharacter character for double quote
	DoubleQuoteCharacter = '"'
	// DirectiveCharacter character for directive
	DirectiveCharacter = '%'
	// SpaceCharacter character for space
	SpaceCharacter = ' '
	// LineBreakCharacter character for line break
	LineBreakCharacter = '\n'
)
View Source
const (
	// IntegerTag `!!int` tag
	IntegerTag ReservedTagKeyword = "!!int"
	// FloatTag `!!float` tag
	FloatTag = "!!float"
	// NullTag `!!null` tag
	NullTag = "!!null"
	// SequenceTag `!!seq` tag
	SequenceTag = "!!seq"
	// MappingTag `!!map` tag
	MappingTag = "!!map"
	// StringTag `!!str` tag
	StringTag = "!!str"
	// BinaryTag `!!binary` tag
	BinaryTag = "!!binary"
	// OrderedMapTag `!!omap` tag
	OrderedMapTag = "!!omap"
	// SetTag `!!set` tag
	SetTag = "!!set"
	// TimestampTag `!!timestamp` tag
	TimestampTag = "!!timestamp"
)

Variables

View Source
var (
	// ReservedTagKeywordMap map for reserved tag keywords
	ReservedTagKeywordMap = map[ReservedTagKeyword]func(string, string, *Position) *Token{
		IntegerTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		FloatTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		NullTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		SequenceTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		MappingTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		StringTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		BinaryTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		OrderedMapTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		SetTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
		TimestampTag: func(value, org string, pos *Position) *Token {
			return &Token{
				Type:          TagType,
				CharacterType: CharacterTypeIndicator,
				Indicator:     NodePropertyIndicator,
				Value:         value,
				Origin:        org,
				Position:      pos,
			}
		},
	}
)

Functions

func IsNeedQuoted

func IsNeedQuoted(value string) bool

IsNeedQuoted whether need quote for passed string or not

Types

type Character

type Character byte

Character type for character

type CharacterType

type CharacterType int

CharacterType type for character category

const (
	// CharacterTypeIndicator type of indicator character
	CharacterTypeIndicator CharacterType = iota
	// CharacterTypeWhiteSpace type of white space character
	CharacterTypeWhiteSpace
	// CharacterTypeMiscellaneous type of miscellaneous character
	CharacterTypeMiscellaneous
	// CharacterTypeEscaped type of escaped character
	CharacterTypeEscaped
)

func (CharacterType) String

func (c CharacterType) String() string

String character type identifier to text

type Indicator

type Indicator int

Indicator type for indicator

const (
	// NotIndicator not indicator
	NotIndicator Indicator = iota
	// BlockStructureIndicator indicator for block structure ( '-', '?', ':' )
	BlockStructureIndicator
	// FlowCollectionIndicator indicator for flow collection ( '[', ']', '{', '}', ',' )
	FlowCollectionIndicator
	// CommentIndicator indicator for comment ( '#' )
	CommentIndicator
	// NodePropertyIndicator indicator for node property ( '!', '&', '*' )
	NodePropertyIndicator
	// BlockScalarIndicator indicator for block scalar ( '|', '>' )
	BlockScalarIndicator
	// QuotedScalarIndicator indicator for quoted scalar ( ”', '"' )
	QuotedScalarIndicator
	// DirectiveIndicator indicator for directive ( '%' )
	DirectiveIndicator
	// InvalidUseOfReservedIndicator indicator for invalid use of reserved keyword ( '@', '`' )
	InvalidUseOfReservedIndicator
)

func (Indicator) String

func (i Indicator) String() string

String indicator to text

type Position

type Position struct {
	Line        int
	Column      int
	Offset      int
	IndentNum   int
	IndentLevel int
}

Position type for position in YAML document

func (*Position) String

func (p *Position) String() string

String position to text

type ReservedTagKeyword

type ReservedTagKeyword string

ReservedTagKeyword type of reserved tag keyword

type Token

type Token struct {
	Type          Type
	CharacterType CharacterType
	Indicator     Indicator
	Value         string
	Origin        string
	Position      *Position
	Next          *Token
	Prev          *Token
}

Token type for token

func Alias

func Alias(org string, pos *Position) *Token

Alias create token for Alias

func Anchor

func Anchor(org string, pos *Position) *Token

Anchor create token for Anchor

func CollectEntry

func CollectEntry(org string, pos *Position) *Token

CollectEntry create token for CollectEntry

func Comment

func Comment(value string, org string, pos *Position) *Token

Comment create token for Comment

func Directive

func Directive(pos *Position) *Token

Directive create token for Directive

func DocumentEnd

func DocumentEnd(pos *Position) *Token

DocumentEnd create token for DocumentEnd

func DocumentHeader

func DocumentHeader(pos *Position) *Token

DocumentHeader create token for DocumentHeader

func DoubleQuote

func DoubleQuote(value string, org string, pos *Position) *Token

DoubleQuote create token for DoubleQuote

func Folded

func Folded(value string, org string, pos *Position) *Token

Folded create token for Folded

func Literal

func Literal(value string, org string, pos *Position) *Token

Literal create token for Literal

func MappingEnd

func MappingEnd(org string, pos *Position) *Token

MappingEnd create token for MappingEnd

func MappingKey

func MappingKey(pos *Position) *Token

MappingKey create token for MappingKey

func MappingStart

func MappingStart(org string, pos *Position) *Token

MappingStart create token for MappingStart

func MappingValue

func MappingValue(pos *Position) *Token

MappingValue create token for MappingValue

func MergeKey

func MergeKey(org string, pos *Position) *Token

MergeKey create token for MergeKey

func New

func New(value string, org string, pos *Position) *Token

New create reserved keyword token or number token and other string token

func SequenceEnd

func SequenceEnd(org string, pos *Position) *Token

SequenceEnd create token for SequenceEnd

func SequenceEntry

func SequenceEntry(org string, pos *Position) *Token

SequenceEntry create token for SequenceEntry

func SequenceStart

func SequenceStart(org string, pos *Position) *Token

SequenceStart create token for SequenceStart

func SingleQuote

func SingleQuote(value string, org string, pos *Position) *Token

SingleQuote create token for SingleQuote

func Space

func Space(pos *Position) *Token

Space create token for Space

func Tag

func Tag(value string, org string, pos *Position) *Token

Tag create token for Tag

func (*Token) NextType

func (t *Token) NextType() Type

NextType next token type

func (*Token) PreviousType

func (t *Token) PreviousType() Type

PreviousType previous token type

type Tokens

type Tokens []*Token

Tokens type of token collection

func (*Tokens) Add

func (t *Tokens) Add(tks ...*Token)

Add append new some tokens

func (Tokens) Dump

func (t Tokens) Dump()

Dump dump all token structures for debugging

type Type

type Type int

Type type identifier for token

const (
	// UnknownType reserve for invalid type
	UnknownType Type = iota
	// DocumentHeaderType type for DocumentHeader token
	DocumentHeaderType
	// DocumentEndType type for DocumentEnd token
	DocumentEndType
	// SequenceEntryType type for SequenceEntry token
	SequenceEntryType
	// MappingKeyType type for MappingKey token
	MappingKeyType
	// MappingValueType type for MappingValue token
	MappingValueType
	// MergeKeyType type for MergeKey token
	MergeKeyType
	// CollectEntryType type for CollectEntry token
	CollectEntryType
	// SequenceStartType type for SequenceStart token
	SequenceStartType
	// SequenceEndType type for SequenceEnd token
	SequenceEndType
	// MappingStartType type for MappingStart token
	MappingStartType
	// MappingEndType type for MappingEnd token
	MappingEndType
	// CommentType type for Comment token
	CommentType
	// AnchorType type for Anchor token
	AnchorType
	// AliasType type for Alias token
	AliasType
	// TagType type for Tag token
	TagType
	// LiteralType type for Literal token
	LiteralType
	// FoldedType type for Folded token
	FoldedType
	// SingleQuoteType type for SingleQuote token
	SingleQuoteType
	// DoubleQuoteType type for DoubleQuote token
	DoubleQuoteType
	// DirectiveType type for Directive token
	DirectiveType
	// SpaceType type for Space token
	SpaceType
	// NullType type for Null token
	NullType
	// InfinityType type for Infinity token
	InfinityType
	// NanType type for Nan token
	NanType
	// IntegerType type for Integer token
	IntegerType
	// BinaryIntegerType type for BinaryInteger token
	BinaryIntegerType
	// OctetIntegerType type for OctetInteger token
	OctetIntegerType
	// HexIntegerType type for HexInteger token
	HexIntegerType
	// FloatType type for Float token
	FloatType
	// StringType type for String token
	StringType
	// BoolType type for Bool token
	BoolType
)

func (Type) String

func (t Type) String() string

String type identifier to text

Jump to

Keyboard shortcuts

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