Help us shape the future of Go! Take the 2026 Go Developer Survey

ast

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAccessorsDetailed added in v0.3.0

func ApplyAccessorsDetailed(value ResolvedValue, accessors []ValueAccessor) (ResolvedValue, AccessError)

func GetArgNameFromCompCallArg added in v0.2.0

func GetArgNameFromCompCallArg(compCallArg Node) string

func GetArgValueFromCompCallArg added in v0.2.0

func GetArgValueFromCompCallArg(compCallArg Node) string

func GetCompValueFrameArgNames added in v0.7.1

func GetCompValueFrameArgNames(node Node) []string

GetCompValueFrameArgNames returns the sorted names of the arguments given to the component value by the comp-value-frame node itself, nil if node is not such a frame or has no arguments.

func GetContextKey added in v0.4.0

func GetContextKey(node Node) string

func GetIndexesFromRaw added in v0.3.0

func GetIndexesFromRaw(raw string) []int

func GetNameFromIndexedRaw added in v0.3.0

func GetNameFromIndexedRaw(raw string) string

func GetParamDefValFromCompParam added in v0.2.0

func GetParamDefValFromCompParam(compParam Node) string

func GetParamNameFromCompParam added in v0.2.0

func GetParamNameFromCompParam(compParam Node) string

func GetParamRefIndexes added in v0.3.0

func GetParamRefIndexes(node Node) []int

func GetParamRefName added in v0.3.0

func GetParamRefName(node Node) string

func GetParamRefRaw added in v0.3.0

func GetParamRefRaw(node Node) string

func GetTypeFromCompCallArg added in v0.2.0

func GetTypeFromCompCallArg(compCallArg Node) string

func GetTypeFromCompParam added in v0.2.0

func GetTypeFromCompParam(compParam Node) string

func IsFrameNode added in v0.7.0

func IsFrameNode(node Node) bool

IsFrameNode reports whether the node renders the content of a component.

func IsRequiredCompParam added in v0.7.0

func IsRequiredCompParam(compParam Node) bool

IsRequiredCompParam reports whether the given component parameter definition marks its parameter as required with a '!' glued to the parameter name, e.g. `title! = ""`. The parameter name itself never contains the '!'.

func IsRuleName

func IsRuleName(node Node, name string) bool

func IsRuleNameOneOf

func IsRuleNameOneOf(node Node, names []string) bool

Types

type AccessError added in v0.3.0

type AccessError struct {
	Kind AccessErrorKind
	Key  string
}

type AccessErrorKind added in v0.4.2

type AccessErrorKind string
const (
	AccessErrorUnknownRecordKey     AccessErrorKind = "unknown_record_key"
	AccessErrorArrayIndexOutOfRange AccessErrorKind = "array_index_out_of_range"
	AccessErrorInvalidKeyAccess     AccessErrorKind = "invalid_key_access"
	AccessErrorInvalidIndexAccess   AccessErrorKind = "invalid_index_access"
)

type BoundArgs added in v0.7.0

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

BoundArgs are the arguments bound to a component value, e.g. menu = menu in MAIN_MENU(menu = menu). They are resolved lazily, in the frame they were written in, no matter where the component value is rendered.

func (*BoundArgs) Arg added in v0.7.0

func (ba *BoundArgs) Arg(name string) Node

Arg returns the bound argument with the given name.

func (*BoundArgs) Args added in v0.7.0

func (ba *BoundArgs) Args() []Node

Args returns the comp-call-arg nodes of the bound arguments.

func (*BoundArgs) WrittenIn added in v0.7.0

func (ba *BoundArgs) WrittenIn() Node

WrittenIn returns the call the bound component value is written in. For a value bound in a default value, it is the call that used the default value.

type Node

type Node interface {
	Rule() rule.Rule
	SetRule(rule.Rule)
	Parent() Node
	SetParent(Node)
	Children() []Node
	SetChildren([]Node)
	HasChildren() bool
	Raw() []byte
	SetRaw([]byte)
	Range() Range
	SetRange(Range)
}

func DefaultEmptyNode

func DefaultEmptyNode() Node

func DefaultRootNode

func DefaultRootNode() Node

func FilterNodes

func FilterNodes(nodes []Node, filter func(Node) bool) []Node

func FilterNodesInDefContent added in v0.7.0

func FilterNodesInDefContent(node Node, filter func(Node) bool) []Node

FilterNodesInDefContent returns nodes matching filter within a definition's content, without entering nested sub-component definitions.

func FilterNodesInTree

func FilterNodesInTree(node Node, filter func(Node) bool) []Node

func FindBuiltinCompDef added in v0.3.0

func FindBuiltinCompDef(root Node, name string) Node

func FindCompDef added in v0.3.0

func FindCompDef(root Node, compCallNode Node, name string) Node

func FindCompDefInScope added in v0.7.0

func FindCompDefInScope(root Node, scope Node, node Node, name string) Node

FindCompDefInScope finds the component a value refers to. Local components are looked up in the scope the value was written in, falling back to the locals of the global component the node belongs to.

func FindFrameCompDef added in v0.7.0

func FindFrameCompDef(root Node, frame Node, invokerAncestors []Node) Node

FindFrameCompDef returns the definition of the component rendered by the frame. invokerAncestors are the invoker ancestors after the frame.

func FindGlobalCompDef

func FindGlobalCompDef(root Node, from Node, name string) Node

FindGlobalCompDef searches the scope chain starting from the enclosing globals of from (innermost first, then their inner scopes), stopping at isolated scopes, and finally checking root.

func FindLocalCompDef

func FindLocalCompDef(srcNode Node, name string) Node

func FindNode

func FindNode(nodes []Node, filter func(Node) bool) Node

func FindNodeByRuleName

func FindNodeByRuleName(nodes []Node, name string) Node

func GetAncestors

func GetAncestors(node Node) []Node

func GetCompCallArgByParamName added in v0.2.0

func GetCompCallArgByParamName(compCallArgs []Node, paramName string) Node

func GetCompCallArgsFromCompCall added in v0.2.0

func GetCompCallArgsFromCompCall(compCall Node) []Node

func GetCompDefHeadFromCompDef added in v0.2.0

func GetCompDefHeadFromCompDef(compDef Node) Node

func GetCompParamsFromCompDef added in v0.2.0

func GetCompParamsFromCompDef(compDef Node) []Node

func GetCompParamsFromCompHead added in v0.2.0

func GetCompParamsFromCompHead(head Node) []Node

func GetLocalCompSourceFromNode added in v0.3.0

func GetLocalCompSourceFromNode(node Node, root Node) Node

func NewCompValueFrame added in v0.7.0

func NewCompValueFrame(value ResolvedValue, parent Node) Node

func NewCompValueFrameWithArgs added in v0.7.0

func NewCompValueFrameWithArgs(value ResolvedValue, parent Node, args map[string]ResolvedValue) Node

NewCompValueFrameWithArgs is NewCompValueFrame with arguments given to the component value by the frame itself, such as the item that LIST gives to its item component.

type Position added in v0.7.0

type Position struct {
	Offset int
	Line   int
	Column int
}

Position is a point in a source: a 0-based byte offset, a 1-based line and a 1-based column counted in runes.

func PositionAt added in v0.7.0

func PositionAt(source []byte, offset int) Position

PositionAt returns the position of the byte offset in source. Lines are separated by \n.

type Range added in v0.7.0

type Range struct {
	Start int
	End   int
}

Range is the [Start, End) byte range of a node in the source it was parsed from. Nodes that were not parsed have the zero Range.

type ResolvedValue added in v0.3.0

type ResolvedValue struct {
	Type              string
	Raw               string
	Items             []ResolvedValue
	Fields            map[string]ResolvedValue
	Scope             Node
	MissingContextKey string
	Bound             *BoundArgs
}

func ApplyAccessors added in v0.3.0

func ApplyAccessors(value ResolvedValue, accessors []ValueAccessor) ResolvedValue

func ApplyIndexes added in v0.3.0

func ApplyIndexes(value ResolvedValue, indexes []int) ResolvedValue

func GetCompValueFrameArg added in v0.7.0

func GetCompValueFrameArg(node Node, name string) (ResolvedValue, bool)

GetCompValueFrameArg returns the argument the comp-value-frame gives to its component value.

func GetCompValueFromFrame added in v0.7.0

func GetCompValueFromFrame(node Node) (ResolvedValue, bool)

func ResolveBoundArg added in v0.7.0

func ResolveBoundArg(root Node, value ResolvedValue, name string) (ResolvedValue, bool)

ResolveBoundArg resolves the argument bound to a component value.

func ResolveCompCallArgValue added in v0.3.0

func ResolveCompCallArgValue(root Node, compCallArg Node, invokerAncestors []Node, currentCompCall Node) ResolvedValue

func ResolveCompParamDefaultFromCompDef added in v0.3.0

func ResolveCompParamDefaultFromCompDef(root Node, compDef Node, paramName string) ResolvedValue

func ResolveContextReferenceValue added in v0.4.0

func ResolveContextReferenceValue(root Node, node Node) ResolvedValue

func ResolveContextValue added in v0.4.0

func ResolveContextValue(root Node, key string) ResolvedValue

func ResolveFrameArg added in v0.7.0

func ResolveFrameArg(root Node, frame Node, paramName string, invokerAncestors []Node) (ResolvedValue, bool)

ResolveFrameArg resolves the argument given to the component rendered by the frame, either by the frame itself or bound to the rendered component value. invokerAncestors are the invoker ancestors after the frame.

func ResolveFrameCompValue added in v0.7.0

func ResolveFrameCompValue(root Node, frame Node, invokerAncestors []Node) ResolvedValue

ResolveFrameCompValue resolves the component value rendered by a param-ref or comp-value-frame frame. invokerAncestors are the invoker ancestors after the frame.

func ResolveFrameParam added in v0.7.0

func ResolveFrameParam(root Node, frame Node, paramName string, invokerAncestors []Node) ResolvedValue

ResolveFrameParam resolves a parameter of the component rendered by the frame: the argument given by the frame, the argument bound to the rendered component value or the default value of the parameter. invokerAncestors are the invoker ancestors after the frame.

func ResolveParamDefaultFromCompCall added in v0.3.0

func ResolveParamDefaultFromCompCall(root Node, compCallNode Node, paramName string) ResolvedValue

func ResolveParamFromAncestors added in v0.3.0

func ResolveParamFromAncestors(root Node, paramName string, accessors []ValueAccessor, invokerAncestors []Node) ResolvedValue

ResolveParamFromAncestors resolves a parameter of the component rendered by the nearest frame in invokerAncestors. There is no parameter inheritance: the lookup never goes past that frame.

func (ResolvedValue) IsZero added in v0.3.0

func (rv ResolvedValue) IsZero() bool

type ValueAccessor added in v0.3.0

type ValueAccessor struct {
	Kind  string
	Key   string
	Index int
}

func GetContextAccessors added in v0.4.0

func GetContextAccessors(node Node) []ValueAccessor

func GetContextPathFromRaw added in v0.4.0

func GetContextPathFromRaw(raw string) (string, []ValueAccessor)

func GetParamRefAccessors added in v0.3.0

func GetParamRefAccessors(node Node) []ValueAccessor

func GetValuePathFromRaw added in v0.3.0

func GetValuePathFromRaw(raw string) (string, []ValueAccessor)

Jump to

Keyboard shortcuts

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