yamlmeta

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package yamlmeta parses YAML streams into a data structure (tree of yamlmeta.Node's) on which comments and metadata can be attached.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewASTFromInterface

func NewASTFromInterface(val interface{}) interface{}

func NewASTFromInterfaceWithNoPosition added in v0.48.0

func NewASTFromInterfaceWithNoPosition(val interface{}) interface{}

func NewASTFromInterfaceWithPosition added in v0.48.0

func NewASTFromInterfaceWithPosition(val interface{}, defaultPosition *filepos.Position) interface{}

func NewGoFromAST added in v0.20.0

func NewGoFromAST(val interface{}) interface{}

func NewValue added in v0.48.0

func NewValue(val interface{}) interface{}

NewValue creates a new Document, Map, Array, or scalar, depending on the type of the given prototype

func PlainMarshal

func PlainMarshal(in interface{}) ([]byte, error)

func PlainUnmarshal

func PlainUnmarshal(data []byte, out interface{}) error

func TypeName added in v0.48.0

func TypeName(val interface{}) string

TypeName returns the user-friendly name of the type of `val`

func Walk added in v0.48.0

func Walk(n Node, v Visitor) error

Walk traverses the tree starting at `n`, recursively, depth-first, invoking `v` on each node. if `v` returns non-nil error, the traversal is aborted.

func WalkWithParent added in v0.48.0

func WalkWithParent(node Node, parent Node, path string, v VisitorWithParent) error

WalkWithParent traverses the tree starting at `n`, recursively, depth-first, invoking `v` on each node and including

a reference to "node"s parent node as well.

if `v` returns non-nil error, the traversal is aborted.

Types

type Array

type Array struct {
	Comments []*Comment
	Items    []*ArrayItem
	Position *filepos.Position
	// contains filtered or unexported fields
}

func NewArray added in v0.48.0

func NewArray(val *ArrayProto) *Array

NewArray creates a new Array instance based on the given prototype

func (*Array) AddValue

func (a *Array) AddValue(val interface{}) error

func (*Array) DeepCopy

func (a *Array) DeepCopy() *Array

func (*Array) DeepCopyAsInterface

func (a *Array) DeepCopyAsInterface() interface{}

func (*Array) DeepCopyAsNode

func (a *Array) DeepCopyAsNode() Node

func (*Array) GetAnnotations

func (a *Array) GetAnnotations() interface{}

func (*Array) GetComments added in v0.48.0

func (a *Array) GetComments() []*Comment

func (*Array) GetMeta added in v0.48.0

func (a *Array) GetMeta(name string) interface{}

GetMeta returns the metadata named `name` that was previously attached via SetMeta()

func (*Array) GetPosition

func (a *Array) GetPosition() *filepos.Position

func (*Array) GetValues

func (a *Array) GetValues() []interface{}

func (*Array) MarshalJSON added in v0.15.0

func (a *Array) MarshalJSON() ([]byte, error)

MarshalJSON panics because Nodes cannot be marshalled directly.

func (*Array) MarshalYAML

func (a *Array) MarshalYAML() (interface{}, error)

MarshalYAML panics because Nodes cannot be marshalled directly.

func (*Array) ResetValue

func (a *Array) ResetValue()

func (*Array) SetAnnotations

func (a *Array) SetAnnotations(anns interface{})

func (*Array) SetComments added in v0.48.0

func (a *Array) SetComments(c []*Comment)

SetComments replaces comments with "c"

func (*Array) SetMeta added in v0.48.0

func (a *Array) SetMeta(name string, data interface{})

SetMeta attaches metadata identified by `name` than can later be retrieved via GetMeta()

func (*Array) SetPosition added in v0.48.0

func (a *Array) SetPosition(position *filepos.Position)

func (*Array) SetValue

func (a *Array) SetValue(val interface{}) error

type ArrayItem

type ArrayItem struct {
	Comments []*Comment
	Value    interface{}
	Position *filepos.Position
	// contains filtered or unexported fields
}

func NewArrayItem added in v0.48.0

func NewArrayItem(val *ArrayItemProto) *ArrayItem

NewArrayItem creates a new ArrayItem instance based on the given prototype

func (*ArrayItem) AddValue

func (ai *ArrayItem) AddValue(val interface{}) error

func (*ArrayItem) DeepCopy

func (ai *ArrayItem) DeepCopy() *ArrayItem

func (*ArrayItem) DeepCopyAsInterface

func (ai *ArrayItem) DeepCopyAsInterface() interface{}

func (*ArrayItem) DeepCopyAsNode

func (ai *ArrayItem) DeepCopyAsNode() Node

func (*ArrayItem) GetAnnotations

func (ai *ArrayItem) GetAnnotations() interface{}

func (*ArrayItem) GetComments added in v0.48.0

func (ai *ArrayItem) GetComments() []*Comment

func (*ArrayItem) GetMeta added in v0.48.0

func (ai *ArrayItem) GetMeta(name string) interface{}

GetMeta returns the metadata named `name` that was previously attached via SetMeta()

func (*ArrayItem) GetPosition

func (ai *ArrayItem) GetPosition() *filepos.Position

func (*ArrayItem) GetValues

func (ai *ArrayItem) GetValues() []interface{}

func (*ArrayItem) MarshalJSON added in v0.15.0

func (ai *ArrayItem) MarshalJSON() ([]byte, error)

MarshalJSON panics because Nodes cannot be marshalled directly.

func (*ArrayItem) MarshalYAML

func (ai *ArrayItem) MarshalYAML() (interface{}, error)

MarshalYAML panics because Nodes cannot be marshalled directly.

func (*ArrayItem) ResetValue

func (ai *ArrayItem) ResetValue()

func (*ArrayItem) SetAnnotations

func (ai *ArrayItem) SetAnnotations(anns interface{})

func (*ArrayItem) SetComments added in v0.48.0

func (ai *ArrayItem) SetComments(c []*Comment)

SetComments replaces comments with "c"

func (*ArrayItem) SetMeta added in v0.48.0

func (ai *ArrayItem) SetMeta(name string, data interface{})

SetMeta attaches metadata identified by `name` than can later be retrieved via GetMeta()

func (*ArrayItem) SetPosition added in v0.48.0

func (ai *ArrayItem) SetPosition(position *filepos.Position)

func (*ArrayItem) SetValue

func (ai *ArrayItem) SetValue(val interface{}) error

type ArrayItemProto added in v0.48.0

type ArrayItemProto struct {
	Value    interface{}
	Comments []*CommentProto
	Position *filepos.Position
}

ArrayItemProto is a prototype for an ArrayItem

type ArrayProto added in v0.48.0

type ArrayProto struct {
	Items    []*ArrayItemProto
	Comments []*CommentProto
	Position *filepos.Position
}

ArrayProto is a prototype for an Array

type Comment added in v0.48.0

type Comment struct {
	Data     string
	Position *filepos.Position
}

func NewComment added in v0.48.0

func NewComment(val *CommentProto) *Comment

NewComment creates a new Comment based on the given prototype

func NewComments added in v0.48.0

func NewComments(val []*CommentProto) []*Comment

NewComments creates a new slice of Comment based on the given prototype

func (*Comment) DeepCopy added in v0.48.0

func (n *Comment) DeepCopy() *Comment

type CommentProto added in v0.48.0

type CommentProto struct {
	Data     string
	Position *filepos.Position
}

CommentProto is a prototype for a Comment

type CommentSlice added in v0.48.0

type CommentSlice []*Comment

func (CommentSlice) DeepCopy added in v0.48.0

func (s CommentSlice) DeepCopy() CommentSlice

type DocSetOpts added in v0.4.0

type DocSetOpts struct {
	WithoutComments bool
	Strict          bool
	// associatedName is typically a file name where data came from
	AssociatedName string
}

type Document

type Document struct {
	Comments []*Comment
	Value    interface{}
	Position *filepos.Position
	// contains filtered or unexported fields
}

func NewDocument added in v0.48.0

func NewDocument(val *DocumentProto) *Document

NewDocument creates a new Document instance based on the given prototype

func (*Document) AddValue

func (d *Document) AddValue(val interface{}) error

func (*Document) AsInterface

func (d *Document) AsInterface() interface{}

func (*Document) AsYAMLBytes added in v0.20.0

func (d *Document) AsYAMLBytes() ([]byte, error)

func (*Document) DeepCopy

func (d *Document) DeepCopy() *Document

func (*Document) DeepCopyAsInterface

func (d *Document) DeepCopyAsInterface() interface{}

func (*Document) DeepCopyAsNode

func (d *Document) DeepCopyAsNode() Node

func (*Document) GetAnnotations

func (d *Document) GetAnnotations() interface{}

func (*Document) GetComments added in v0.48.0

func (d *Document) GetComments() []*Comment

func (*Document) GetMeta added in v0.48.0

func (d *Document) GetMeta(name string) interface{}

GetMeta returns the metadata named `name` that was previously attached via SetMeta()

func (*Document) GetPosition

func (d *Document) GetPosition() *filepos.Position

func (*Document) GetValues

func (d *Document) GetValues() []interface{}

func (*Document) IsEmpty

func (d *Document) IsEmpty() bool

func (*Document) MarshalJSON added in v0.15.0

func (d *Document) MarshalJSON() ([]byte, error)

MarshalJSON panics because Nodes cannot be marshalled directly.

func (*Document) MarshalYAML

func (d *Document) MarshalYAML() (interface{}, error)

MarshalYAML panics because Nodes cannot be marshalled directly.

func (*Document) ResetValue

func (d *Document) ResetValue()

func (*Document) SetAnnotations

func (d *Document) SetAnnotations(anns interface{})

func (*Document) SetComments added in v0.48.0

func (d *Document) SetComments(c []*Comment)

SetComments replaces comments with "c"

func (*Document) SetMeta added in v0.48.0

func (d *Document) SetMeta(name string, data interface{})

SetMeta attaches metadata identified by `name` than can later be retrieved via GetMeta()

func (*Document) SetPosition added in v0.48.0

func (d *Document) SetPosition(position *filepos.Position)

func (*Document) SetValue

func (d *Document) SetValue(val interface{}) error

type DocumentPrinter added in v0.14.0

type DocumentPrinter interface {
	Print(*Document) error
}

type DocumentProto added in v0.48.0

type DocumentProto struct {
	Value    interface{}
	Comments []*CommentProto
	Position *filepos.Position
}

DocumentProto is a prototype for a Document

type DocumentSet

type DocumentSet struct {
	Comments    []*Comment
	AllComments []*Comment

	Items    []*Document
	Position *filepos.Position
	// contains filtered or unexported fields
}

func NewDocumentSet added in v0.48.0

func NewDocumentSet(val *DocumentSetProto) *DocumentSet

NewDocumentSet creates a new DocumentSet instance based on the given prototype

func NewDocumentSetFromBytes

func NewDocumentSetFromBytes(data []byte, opts DocSetOpts) (*DocumentSet, error)

func (*DocumentSet) AddValue

func (ds *DocumentSet) AddValue(val interface{}) error

func (*DocumentSet) AsBytes

func (ds *DocumentSet) AsBytes() ([]byte, error)

func (*DocumentSet) AsBytesWithPrinter added in v0.14.0

func (ds *DocumentSet) AsBytesWithPrinter(printerFunc func(io.Writer) DocumentPrinter) ([]byte, error)

func (*DocumentSet) AsSourceBytes

func (ds *DocumentSet) AsSourceBytes() ([]byte, bool)

AsSourceBytes() returns bytes used to make original DocumentSet. Any changes made to the DocumentSet are not reflected in any way

func (*DocumentSet) DeepCopy

func (ds *DocumentSet) DeepCopy() *DocumentSet

func (*DocumentSet) DeepCopyAsInterface

func (ds *DocumentSet) DeepCopyAsInterface() interface{}

func (*DocumentSet) DeepCopyAsNode

func (ds *DocumentSet) DeepCopyAsNode() Node

func (*DocumentSet) GetAnnotations

func (ds *DocumentSet) GetAnnotations() interface{}

func (*DocumentSet) GetComments added in v0.48.0

func (ds *DocumentSet) GetComments() []*Comment

func (*DocumentSet) GetMeta added in v0.48.0

func (ds *DocumentSet) GetMeta(name string) interface{}

GetMeta returns the metadata named `name` that was previously attached via SetMeta()

func (*DocumentSet) GetPosition

func (ds *DocumentSet) GetPosition() *filepos.Position

func (*DocumentSet) GetValues

func (ds *DocumentSet) GetValues() []interface{}

func (*DocumentSet) MarshalJSON added in v0.15.0

func (ds *DocumentSet) MarshalJSON() ([]byte, error)

MarshalJSON panics because Nodes cannot be marshalled directly.

func (*DocumentSet) MarshalYAML

func (ds *DocumentSet) MarshalYAML() (interface{}, error)

MarshalYAML panics because Nodes cannot be marshalled directly.

func (*DocumentSet) OverrideMapKeys added in v0.48.0

func (ds *DocumentSet) OverrideMapKeys()

OverrideMapKeys within any contained Map, where there is more than one MapItem with the same key, delete all but the last.

func (*DocumentSet) Print

func (ds *DocumentSet) Print(writer io.Writer)

func (*DocumentSet) ResetValue

func (ds *DocumentSet) ResetValue()

func (*DocumentSet) SetAnnotations

func (ds *DocumentSet) SetAnnotations(anns interface{})

func (*DocumentSet) SetComments added in v0.48.0

func (ds *DocumentSet) SetComments(c []*Comment)

SetComments replaces comments with "c"

func (*DocumentSet) SetMeta added in v0.48.0

func (ds *DocumentSet) SetMeta(name string, data interface{})

SetMeta attaches metadata identified by `name` than can later be retrieved via GetMeta()

func (*DocumentSet) SetPosition added in v0.48.0

func (ds *DocumentSet) SetPosition(position *filepos.Position)

func (*DocumentSet) SetValue

func (ds *DocumentSet) SetValue(val interface{}) error

type DocumentSetProto added in v0.48.0

type DocumentSetProto struct {
	Items    []*DocumentProto
	Comments []*CommentProto
	Position *filepos.Position
}

DocumentSetProto is a prototype for a DocumentSet

type FilePositionPrinter added in v0.14.0

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

func NewFilePositionPrinter added in v0.14.0

func NewFilePositionPrinter(writer io.Writer) *FilePositionPrinter

func NewFilePositionPrinterWithOpts added in v0.14.0

func NewFilePositionPrinterWithOpts(writer io.Writer, opts FilePositionPrinterOpts) *FilePositionPrinter

func (*FilePositionPrinter) Print added in v0.14.0

func (p *FilePositionPrinter) Print(val interface{})

func (*FilePositionPrinter) PrintStr added in v0.14.0

func (p *FilePositionPrinter) PrintStr(val interface{}) string

type FilePositionPrinterOpts added in v0.14.0

type FilePositionPrinterOpts struct{}

type JSONPrinter added in v0.14.0

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

func NewJSONPrinter added in v0.14.0

func NewJSONPrinter(writer io.Writer) JSONPrinter

func (JSONPrinter) Print added in v0.14.0

func (p JSONPrinter) Print(item *Document) error

type Map

type Map struct {
	Comments []*Comment
	Items    []*MapItem
	Position *filepos.Position
	// contains filtered or unexported fields
}

func NewMap added in v0.48.0

func NewMap(val *MapProto) *Map

NewMap creates a new Map instance based on the given prototype

func (*Map) AddValue

func (m *Map) AddValue(val interface{}) error

func (*Map) DeepCopy

func (m *Map) DeepCopy() *Map

func (*Map) DeepCopyAsInterface

func (m *Map) DeepCopyAsInterface() interface{}

func (*Map) DeepCopyAsNode

func (m *Map) DeepCopyAsNode() Node

func (*Map) GetAnnotations

func (m *Map) GetAnnotations() interface{}

func (*Map) GetComments added in v0.48.0

func (m *Map) GetComments() []*Comment

func (*Map) GetMeta added in v0.48.0

func (m *Map) GetMeta(name string) interface{}

GetMeta returns the metadata named `name` that was previously attached via SetMeta()

func (*Map) GetPosition

func (m *Map) GetPosition() *filepos.Position

func (*Map) GetValues

func (m *Map) GetValues() []interface{}

func (*Map) MarshalJSON added in v0.15.0

func (m *Map) MarshalJSON() ([]byte, error)

MarshalJSON panics because Nodes cannot be marshalled directly.

func (*Map) MarshalYAML

func (m *Map) MarshalYAML() (interface{}, error)

MarshalYAML panics because Nodes cannot be marshalled directly.

func (*Map) ResetValue

func (m *Map) ResetValue()

func (*Map) SetAnnotations

func (m *Map) SetAnnotations(anns interface{})

func (*Map) SetComments added in v0.48.0

func (m *Map) SetComments(c []*Comment)

SetComments replaces comments with "c"

func (*Map) SetMeta added in v0.48.0

func (m *Map) SetMeta(name string, data interface{})

SetMeta attaches metadata identified by `name` than can later be retrieved via GetMeta()

func (*Map) SetPosition added in v0.48.0

func (m *Map) SetPosition(position *filepos.Position)

func (*Map) SetValue

func (m *Map) SetValue(val interface{}) error

type MapItem

type MapItem struct {
	Comments []*Comment
	Key      interface{}
	Value    interface{}
	Position *filepos.Position
	// contains filtered or unexported fields
}

func NewMapItem added in v0.48.0

func NewMapItem(val *MapItemProto) *MapItem

NewMapItem creates a new MapItem instance based on the given prototype

func (*MapItem) AddValue

func (mi *MapItem) AddValue(val interface{}) error

func (*MapItem) DeepCopy

func (mi *MapItem) DeepCopy() *MapItem

func (*MapItem) DeepCopyAsInterface

func (mi *MapItem) DeepCopyAsInterface() interface{}

func (*MapItem) DeepCopyAsNode

func (mi *MapItem) DeepCopyAsNode() Node

func (*MapItem) GetAnnotations

func (mi *MapItem) GetAnnotations() interface{}

func (*MapItem) GetComments added in v0.48.0

func (mi *MapItem) GetComments() []*Comment

func (*MapItem) GetMeta added in v0.48.0

func (mi *MapItem) GetMeta(name string) interface{}

GetMeta returns the metadata named `name` that was previously attached via SetMeta()

func (*MapItem) GetPosition

func (mi *MapItem) GetPosition() *filepos.Position

func (*MapItem) GetValues

func (mi *MapItem) GetValues() []interface{}

func (*MapItem) MarshalJSON added in v0.15.0

func (mi *MapItem) MarshalJSON() ([]byte, error)

MarshalJSON panics because Nodes cannot be marshalled directly.

func (*MapItem) MarshalYAML

func (mi *MapItem) MarshalYAML() (interface{}, error)

MarshalYAML panics because Nodes cannot be marshalled directly.

func (*MapItem) ResetValue

func (mi *MapItem) ResetValue()

func (*MapItem) SetAnnotations

func (mi *MapItem) SetAnnotations(anns interface{})

func (*MapItem) SetComments added in v0.48.0

func (mi *MapItem) SetComments(c []*Comment)

SetComments replaces comments with "c"

func (*MapItem) SetMeta added in v0.48.0

func (mi *MapItem) SetMeta(name string, data interface{})

SetMeta attaches metadata identified by `name` than can later be retrieved via GetMeta()

func (*MapItem) SetPosition added in v0.48.0

func (mi *MapItem) SetPosition(position *filepos.Position)

func (*MapItem) SetValue

func (mi *MapItem) SetValue(val interface{}) error

type MapItemProto added in v0.48.0

type MapItemProto struct {
	Key      interface{}
	Value    interface{}
	Comments []*CommentProto
	Position *filepos.Position
}

MapItemProto is a prototype for a MapItem

type MapProto added in v0.48.0

type MapProto struct {
	Items    []*MapItemProto
	Comments []*CommentProto
	Position *filepos.Position
}

MapProto is a prototype for a Map

type Node

type Node interface {
	GetPosition() *filepos.Position
	SetPosition(*filepos.Position)

	GetValues() []interface{} // ie children
	SetValue(interface{}) error
	AddValue(interface{}) error
	ResetValue()

	GetComments() []*Comment
	SetComments([]*Comment)

	GetMeta(name string) interface{}
	SetMeta(name string, data interface{})
	GetAnnotations() interface{}
	SetAnnotations(interface{})

	DeepCopyAsInterface() interface{}
	DeepCopyAsNode() Node
	// contains filtered or unexported methods
}

type Parser

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

func NewParser

func NewParser(opts ParserOpts) *Parser

func (*Parser) ParseBytes

func (p *Parser) ParseBytes(data []byte, associatedName string) (*DocumentSet, error)

type ParserOpts added in v0.17.0

type ParserOpts struct {
	WithoutComments bool
	Strict          bool
}

type Printer

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

func NewPrinter

func NewPrinter(writer io.Writer) Printer

func NewPrinterWithOpts

func NewPrinterWithOpts(writer io.Writer, opts PrinterOpts) Printer

func (Printer) Print

func (p Printer) Print(val interface{})

func (Printer) PrintStr

func (p Printer) PrintStr(val interface{}) string

type PrinterOpts

type PrinterOpts struct {
	ExcludeRefs    bool
	IncludeSrcLine bool
}

type Visitor added in v0.48.0

type Visitor interface {
	Visit(Node) error
}

Visitor performs an operation on the given Node while traversing the AST. Typically defines the action taken during a Walk().

type VisitorWithParent added in v0.48.0

type VisitorWithParent interface {
	VisitWithParent(value Node, parent Node, path string) error
}

VisitorWithParent performs an operation on the given Node while traversing the AST, including a reference to "node"'s

parent node.

Typically defines the action taken during a WalkWithParent().

type WrappedFilePositionPrinter added in v0.14.0

type WrappedFilePositionPrinter struct {
	Printer *FilePositionPrinter
}

func (WrappedFilePositionPrinter) Print added in v0.14.0

func (p WrappedFilePositionPrinter) Print(item *Document) error

type YAMLPrinter added in v0.14.0

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

func NewYAMLPrinter added in v0.14.0

func NewYAMLPrinter(writer io.Writer) *YAMLPrinter

func (*YAMLPrinter) Print added in v0.14.0

func (p *YAMLPrinter) Print(item *Document) error

Directories

Path Synopsis
internal
yaml.v2
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.

Jump to

Keyboard shortcuts

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