ast

package
v0.0.0-...-8512979 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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) IsLast

func (c *Iterator) IsLast() bool

IsLast returns true if the current node of the iterator is the last one. Subsequent call to Next() will return false.

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
	LocalTime
	LocalDateTime
	DateTime
)

func (Kind) String

func (k Kind) String() string

type Node

type Node struct {
	Kind Kind
	Raw  Range  // Raw bytes from the input.
	Data []byte // Node value (either allocated or referencing 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).

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 Range

type Range struct {
	Offset uint32
	Length uint32
}

type Reference

type Reference int
const InvalidReference Reference = -1

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.

Jump to

Keyboard shortcuts

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