package ast

import "github.com/pelletier/go-toml/v2/internal/ast"

Index

Types

type Builder

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

func (*Builder) AttachChild

func (b *Builder) AttachChild(parent Reference, child Reference)

func (*Builder) Chain

func (b *Builder) Chain(from Reference, to Reference)

func (*Builder) NodeAt

func (b *Builder) NodeAt(ref Reference) Node

func (*Builder) Push

func (b *Builder) Push(n Node) Reference

func (*Builder) PushAndChain

func (b *Builder) PushAndChain(n Node) Reference

func (*Builder) Reset

func (b *Builder) Reset()

func (*Builder) Tree

func (b *Builder) Tree() *Root

type Iterator

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

Iterator starts uninitialized, you need to call Next() first.

For example:

it := n.Children()

for it.Next() {
		it.Node()
}

func (*Iterator) Next

func (c *Iterator) Next() bool

Next moves the iterator forward and returns true if points to a node, false otherwise.

func (*Iterator) Node

func (c *Iterator) Node() Node

Node returns a copy of the node pointed at by the iterator.

type Kind

type Kind int
const (
	// meta
	Invalid Kind = iota
	Comment
	Key

	// top level structures
	Table
	ArrayTable
	KeyValue

	// containers values
	Array
	InlineTable

	// values
	String
	Bool
	Float
	Integer
	LocalDate
	LocalDateTime
	DateTime
	Time
)

func (Kind) String

func (k Kind) String() string

type Node

type Node struct {
	Kind Kind
	Data []byte // Raw bytes from the input
	// contains filtered or unexported fields
}

Arrays have one child per element in the array. InlineTables have one child per key-value pair in the table. KeyValues have at least two children. The first one is the value. The rest make a potentially dotted key. Table and Array table have one child per element of the key they represent (same as KeyValue, but without the last node being the value). children []Node

func (Node) Child

func (n Node) Child() Node

Child returns a copy of the first child node of this node. Other children can be accessed calling Next on the first child. Returns an invalid Node if there is none.

func (Node) Children

func (n Node) Children() Iterator

Children returns an iterator over a node's children.

func (*Node) Key

func (n *Node) Key() Iterator

Key returns the child nodes making the Key on a supported node. Panics otherwise. They are guaranteed to be all be of the Kind Key. A simple key would return just one element.

func (Node) Next

func (n Node) Next() Node

Next returns a copy of the next node, or an invalid Node if there is no next node.

func (Node) Valid

func (n Node) Valid() bool

Valid returns true if the node's kind is set (not to Invalid).

func (Node) Value

func (n Node) Value() Node

Value returns a pointer to the value node of a KeyValue. Guaranteed to be non-nil. Panics if not called on a KeyValue node, or if the Children are malformed.

type Reference

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

func (Reference) Valid

func (r Reference) Valid() bool

type Root

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

Root contains a full AST.

It is immutable once constructed with Builder.

func (*Root) Iterator

func (r *Root) Iterator() Iterator

Iterator over the top level nodes.

Source Files

ast.go builder.go kind.go

Version
v2.0.0-beta.2
Published
May 11, 2021
Platform
darwin/amd64
Imports
1 packages
Last checked
12 hours ago

Tools for package owners.