syntax

package
v0.11.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoSyntax = noSyntax(0)

Functions

func AsNumber

func AsNumber[T NumberValue](v T) json.Number

AsNumber converts the input value to a json.Number.

func Walk added in v0.6.0

func Walk(n Node, visitor func(n Node) (Node, Diagnostics, error)) (Node, Diagnostics, error)

Walk recursively walks the tree rooted at the given node. The visitor is called after the Node's descendants have been walked (i.e. visitation is post-order).

Types

type ArrayNode added in v0.5.5

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

A ArrayNode represents an array of nodes.

func Array added in v0.5.5

func Array(elements ...Node) *ArrayNode

Array creates a new array node with the given elements.

func ArraySyntax added in v0.5.5

func ArraySyntax(syntax Syntax, elements ...Node) *ArrayNode

ArraySyntax creates a new array node with the given elements and associated syntax.

func (*ArrayNode) GoString added in v0.5.5

func (n *ArrayNode) GoString() string

func (*ArrayNode) Index added in v0.5.5

func (n *ArrayNode) Index(i int) Node

Index returns the i'th element of the array.

func (*ArrayNode) Len added in v0.5.5

func (n *ArrayNode) Len() int

Len returns the number of elements in the array.

func (*ArrayNode) SetIndex added in v0.5.5

func (n *ArrayNode) SetIndex(i int, v Node)

SetIndex sets the i'th property of the array.

func (*ArrayNode) String added in v0.5.5

func (n *ArrayNode) String() string

func (*ArrayNode) Syntax added in v0.5.5

func (n *ArrayNode) Syntax() Syntax

type BooleanNode

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

A BooleanNode represents a boolean literal.

func Boolean

func Boolean(value bool) *BooleanNode

Boolean creates a new boolean literal node with the given value.

func BooleanSyntax

func BooleanSyntax(syntax Syntax, value bool) *BooleanNode

BooleanSyntax creates a new boolean literal node with the given value and associated syntax.

func (*BooleanNode) GoString added in v0.5.5

func (n *BooleanNode) GoString() string

func (*BooleanNode) String

func (n *BooleanNode) String() string

func (*BooleanNode) Syntax

func (n *BooleanNode) Syntax() Syntax

func (*BooleanNode) Value

func (n *BooleanNode) Value() bool

Value returns the boolean literal's value.

type Diagnostic

type Diagnostic struct {
	hcl.Diagnostic

	Path string
}

A Diagnostic represents a warning or an error to be presented to the user.

func Error

func Error(rng *hcl.Range, summary, path string) *Diagnostic

Error creates a new error-level diagnostic from the given subject, summary, and detail.

func NodeError

func NodeError(node Node, summary string) *Diagnostic

NodeError creates a new error-level diagnostic from the given node, summary, and detail. If the node is non-nil, the diagnostic will be associated with the range of its associated syntax, if any.

type Diagnostics

type Diagnostics []*Diagnostic

Diagnostics is a list of diagnostics.

func (Diagnostics) Error

func (d Diagnostics) Error() string

Error implements the error interface so that Diagnostics values may interoperate with APIs that use errors.

func (*Diagnostics) Extend

func (d *Diagnostics) Extend(diags ...*Diagnostic)

Extend appends the given list of diagnostics to the list.

func (Diagnostics) HasErrors

func (d Diagnostics) HasErrors() bool

HasErrors returns true if the list of diagnostics contains any error-level diagnostics.

type Node

type Node interface {
	fmt.Stringer
	fmt.GoStringer

	Syntax() Syntax
	// contains filtered or unexported methods
}

A Node represents a single node in an object tree.

type NullNode

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

A NullNode represents a null literal.

func Null

func Null() *NullNode

Null creates a new null literal node.

func NullSyntax

func NullSyntax(syntax Syntax) *NullNode

NullSyntax creates a new null literal node with associated syntax.

func (*NullNode) GoString added in v0.5.5

func (*NullNode) GoString() string

func (*NullNode) String

func (*NullNode) String() string

func (*NullNode) Syntax

func (n *NullNode) Syntax() Syntax

type NumberNode

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

A NumberNode represents a number literal.

func Number

func Number[T NumberValue](value T) *NumberNode

Number creates a new number literal node with the given value.

func NumberSyntax

func NumberSyntax[T NumberValue](syntax Syntax, value T) *NumberNode

NumberSyntax creates a new number literal node with the given value and associated syntax.

func (*NumberNode) GoString added in v0.5.5

func (n *NumberNode) GoString() string

func (*NumberNode) String

func (n *NumberNode) String() string

func (*NumberNode) Syntax

func (n *NumberNode) Syntax() Syntax

func (*NumberNode) Value

func (n *NumberNode) Value() json.Number

Value returns the number literal's value.

type NumberValue

type NumberValue interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64 | json.Number
}

NumberValue describes the set of types that can be represented as a number.

type ObjectNode

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

An ObjectNode represents an object. An object is a list of key-value pairs where the keys are string literals and the values are arbitrary nodes.

func Object

func Object(entries ...ObjectPropertyDef) *ObjectNode

Object creates a new object node with the given properties.

func ObjectSyntax

func ObjectSyntax(syntax Syntax, entries ...ObjectPropertyDef) *ObjectNode

ObjectSyntax creates a new object node with the given properties and associated syntax.

func (*ObjectNode) GoString added in v0.5.5

func (n *ObjectNode) GoString() string

func (*ObjectNode) Index

func (n *ObjectNode) Index(i int) ObjectPropertyDef

Index returns the i'th property of the object.

func (*ObjectNode) Len

func (n *ObjectNode) Len() int

Len returns the number of properties in the object.

func (*ObjectNode) SetIndex added in v0.5.5

func (n *ObjectNode) SetIndex(i int, prop ObjectPropertyDef)

SetIndex sets the i'th property of the object.

func (*ObjectNode) String

func (n *ObjectNode) String() string

func (*ObjectNode) Syntax

func (n *ObjectNode) Syntax() Syntax

type ObjectPropertyDef

type ObjectPropertyDef struct {
	Syntax Syntax      // The syntax associated with the property, if any.
	Key    *StringNode // The name of the property.
	Value  Node        // The value of the property.
}

An ObjectPropertyDef represents a property definition in an object.

func ObjectProperty

func ObjectProperty(key *StringNode, value Node) ObjectPropertyDef

ObjectProperty creates a new object property definition with the given key and value.

func ObjectPropertySyntax

func ObjectPropertySyntax(syntax Syntax, key *StringNode, value Node) ObjectPropertyDef

ObjectPropertySyntax creates a new object property definition with the given key, value, and associated syntax.

func (ObjectPropertyDef) GoString added in v0.5.5

func (d ObjectPropertyDef) GoString() string

type Scalar added in v0.8.0

type Scalar interface {
	Syntax

	ScalarRange(start, end int) *hcl.Range
}

type StringNode

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

A StringNode represents a string literal.

func String

func String(value string) *StringNode

String creates a new string literal node with the given value.

func StringSyntax

func StringSyntax(syntax Syntax, value string) *StringNode

String creates a new string literal node with the given value and associated syntax.

func (*StringNode) GoString added in v0.5.5

func (n *StringNode) GoString() string

func (*StringNode) String

func (n *StringNode) String() string

String returns the string literal's value.

func (*StringNode) Syntax

func (n *StringNode) Syntax() Syntax

func (*StringNode) Value

func (n *StringNode) Value() string

Value returns the string literal's value.

type Syntax

type Syntax interface {
	Range() *hcl.Range
	Path() string
}

func CopyTrivia added in v0.6.0

func CopyTrivia(s Syntax) Syntax

type Trivia

type Trivia interface {
	Syntax

	HeadComment() string
	LineComment() string
	FootComment() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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