ast

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: 1 Imported by: 0

Documentation

Overview

Package ast contains types for YAML AST representation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidNode

func ValidNode(n Node) bool

ValidNode checks if Node is valid and can be processed.

Types

type AliasNode

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

func NewAliasNode

func NewAliasNode(text string) *AliasNode

func (*AliasNode) Accept

func (a *AliasNode) Accept(v Visitor)

func (*AliasNode) Text

func (a *AliasNode) Text() string

func (*AliasNode) Type

func (*AliasNode) Type() NodeType

type AnchorNode

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

func NewAnchorNode

func NewAnchorNode(text string) *AnchorNode

func (*AnchorNode) Accept

func (a *AnchorNode) Accept(v Visitor)

func (*AnchorNode) Text

func (a *AnchorNode) Text() string

func (*AnchorNode) Type

func (*AnchorNode) Type() NodeType

type BasicNode

type BasicNode struct {
	NodeType NodeType
}

BasicNode is a simple container for given type and used during parsing.

func NewBasicNode

func NewBasicNode(tp NodeType) *BasicNode

func (*BasicNode) Accept

func (*BasicNode) Accept(Visitor)

func (*BasicNode) Type

func (b *BasicNode) Type() NodeType

type BlockHeaderNode

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

func NewBlockHeaderNode

func NewBlockHeaderNode(chomping ChompingType, indentation int) *BlockHeaderNode

func (*BlockHeaderNode) Accept

func (*BlockHeaderNode) Accept(Visitor)

func (*BlockHeaderNode) ChompingIndicator

func (b *BlockHeaderNode) ChompingIndicator() ChompingType

ChompingIndicator returns a chomping type defines in block header.

func (*BlockHeaderNode) IndentationIndicator

func (b *BlockHeaderNode) IndentationIndicator() int

IndentationIndicator returns an indentation value that was explicitly set in block header.

func (*BlockHeaderNode) Type

func (*BlockHeaderNode) Type() NodeType

type ChompingType

type ChompingType int8

ChompingType corresponds to YAML chomping type and defines what to do with trailing newlines in literal/folded style.

const (
	UnknownChompingType ChompingType = iota
	// ClipChompingType prescribes removing of trailing newlines except the first one
	ClipChompingType
	// StripChompingType prescribes removing of all trailing newlines
	StripChompingType
	// KeepChompingType prescribes keeping of all trailing newlines
	KeepChompingType
)

func TokenChompingType

func TokenChompingType(tok token.Token) ChompingType

TokenChompingType derives chomping type from given token

type ContentNode

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

func NewContentNode

func NewContentNode(properties, content Node) *ContentNode

func (*ContentNode) Accept

func (c *ContentNode) Accept(v Visitor)

func (*ContentNode) Content

func (c *ContentNode) Content() Node

func (*ContentNode) Properties

func (c *ContentNode) Properties() Node

func (*ContentNode) Type

func (*ContentNode) Type() NodeType

type IndentNode

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

func NewIndentNode

func NewIndentNode(indent int) *IndentNode

func (*IndentNode) Accept

func (*IndentNode) Accept(Visitor)

func (*IndentNode) Indent

func (i *IndentNode) Indent() int

func (*IndentNode) Type

func (*IndentNode) Type() NodeType

type MappingEntryNode

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

func NewMappingEntryNode

func NewMappingEntryNode(key, value Node) *MappingEntryNode

func (*MappingEntryNode) Accept

func (m *MappingEntryNode) Accept(v Visitor)

func (*MappingEntryNode) Key

func (m *MappingEntryNode) Key() Node

func (*MappingEntryNode) SetKey

func (m *MappingEntryNode) SetKey(n Node)

func (*MappingEntryNode) SetValue

func (m *MappingEntryNode) SetValue(n Node)

func (*MappingEntryNode) Type

func (*MappingEntryNode) Type() NodeType

func (*MappingEntryNode) Value

func (m *MappingEntryNode) Value() Node

type MappingNode

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

func NewMappingNode

func NewMappingNode(entries []Node) *MappingNode

func (*MappingNode) Accept

func (m *MappingNode) Accept(v Visitor)

func (*MappingNode) AppendEntry

func (m *MappingNode) AppendEntry(n Node)

func (*MappingNode) Entries

func (m *MappingNode) Entries() []Node

func (*MappingNode) Type

func (*MappingNode) Type() NodeType

type Node

type Node interface {
	// Type returns the node's type
	Type() NodeType
	// Accept implements "Visitor" pattern for AST.
	Accept(v Visitor)
}

Node is a single element of YAML AST

func NewInvalidNode

func NewInvalidNode() Node

type NodeType

type NodeType int8

NodeType represents the type of element in AST

const (
	// InvalidType embodies an erroneous element of AST. They usually appear when an error occures during parsing.
	InvalidType NodeType = iota
	// DocumentType represents a YAML document.
	DocumentType
	// ContentType represents a content element (scalar, sequence or mapping) with properties (tag, anchor).
	ContentType
	// MappingType represents a YAML mapping.
	MappingType
	// MappingEntryType represents a single mapping entry (key-value pair).
	MappingEntryType
	// SequenceType represents a YAML sequence.
	SequenceType
	// CommentType represents a YAML comment.
	CommentType
	// DirectiveType represents a YAML directive.
	DirectiveType
	// TagType represents a YAML tag.
	TagType
	// AnchorType represents a YAML anchor.
	AnchorType
	// AliasType represents a YAML alias.
	AliasType
	// StreamType represents a YAML stream
	StreamType
	// DocumentPrefixType represents a YAML document prefix (BOM + comments)
	DocumentPrefixType
	// DocumentSuffixType represents a YAML document suffix (document end + comments)
	DocumentSuffixType
	// IndentType represents a YAML indentation.
	IndentType
	// PropertiesType represents element's properties (tag, anchor).
	PropertiesType
	// BlockHeaderType represents literal/folded properties (chomping, explicit indent indicator)
	BlockHeaderType
	// TextType represents a text, i.e. single scalar
	TextType
	// NullType represents a null scalar.
	NullType
)

func (NodeType) String

func (t NodeType) String() string

type NullNode

type NullNode struct{}

func NewNullNode

func NewNullNode() *NullNode

func (*NullNode) Accept

func (n *NullNode) Accept(v Visitor)

func (*NullNode) Type

func (*NullNode) Type() NodeType

type PropertiesNode

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

func NewPropertiesNode

func NewPropertiesNode(tag, anchor Node) *PropertiesNode

func (*PropertiesNode) Accept

func (p *PropertiesNode) Accept(v Visitor)

func (*PropertiesNode) Anchor

func (p *PropertiesNode) Anchor() Node

func (*PropertiesNode) Tag

func (p *PropertiesNode) Tag() Node

func (*PropertiesNode) Type

func (*PropertiesNode) Type() NodeType

type QuotingType

type QuotingType int8

QuotingType represents a quoting type of string.

const (
	UnknownQuotingType QuotingType = iota
	// AbsentQuotingType means that string has no quotes
	AbsentQuotingType
	// SingleQuotingType means that string is enclosed in single quotes
	SingleQuotingType
	// DoubleQuotingType means that string is enclosed in double quotes
	DoubleQuotingType
)

type SequenceNode

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

func NewSequenceNode

func NewSequenceNode(entries []Node) *SequenceNode

func (*SequenceNode) Accept

func (s *SequenceNode) Accept(v Visitor)

func (*SequenceNode) AppendEntry

func (s *SequenceNode) AppendEntry(n Node)

func (*SequenceNode) Entries

func (s *SequenceNode) Entries() []Node

func (*SequenceNode) Type

func (*SequenceNode) Type() NodeType

type StreamNode

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

func NewStreamNode

func NewStreamNode(documents []Node) *StreamNode

func (*StreamNode) Accept

func (s *StreamNode) Accept(v Visitor)

func (*StreamNode) Documents

func (s *StreamNode) Documents() []Node

func (*StreamNode) Type

func (*StreamNode) Type() NodeType

type TagNode

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

func NewTagNode

func NewTagNode(text string) *TagNode

func (*TagNode) Accept

func (t *TagNode) Accept(v Visitor)

func (*TagNode) Text

func (t *TagNode) Text() string

func (*TagNode) Type

func (*TagNode) Type() NodeType

type TextNode

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

func NewTextNode

func NewTextNode(text string, opts ...TextNodeOption) *TextNode

func (*TextNode) Accept

func (t *TextNode) Accept(v Visitor)

func (*TextNode) QuotingType

func (t *TextNode) QuotingType() QuotingType

func (*TextNode) Text

func (t *TextNode) Text() string

func (*TextNode) Type

func (*TextNode) Type() NodeType

type TextNodeOption

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

TextNodeOption allows to modify YAML element associated with TextNode during creation.

func WithQuotingType

func WithQuotingType(t QuotingType) TextNodeOption

WithQuotingType sets given QuotingType for TextNode string.

type Texter

type Texter interface {
	// Text returns string data associated with Texter node
	Text() string
}

Texter is a more specific kind of Node that has some meaningful string data

type TexterNode

type TexterNode interface {
	Texter
	Node
}

TexterNode is a composite of Node and Texter interfaces

type Visitor

type Visitor interface {
	VisitStreamNode(n *StreamNode)
	VisitTagNode(n *TagNode)
	VisitAnchorNode(n *AnchorNode)
	VisitAliasNode(n *AliasNode)
	VisitTextNode(n *TextNode)
	VisitSequenceNode(n *SequenceNode)
	VisitMappingNode(n *MappingNode)
	VisitMappingEntryNode(n *MappingEntryNode)
	VisitNullNode(n *NullNode)
	VisitPropertiesNode(n *PropertiesNode)
	VisitContentNode(n *ContentNode)
}

Visitor implements "Visitor" pattern and allows to traverse AST with some custom logic

Directories

Path Synopsis
Package astcmp contains types and method to compare YAML ASTs.
Package astcmp contains types and method to compare YAML ASTs.
Package astprint contains types and functions for printing and formatting string representation of YAML AST.
Package astprint contains types and functions for printing and formatting string representation of YAML AST.

Jump to

Keyboard shortcuts

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