Documentation ¶
Index ¶
- func Dereference(root ast.Node, path protopath.Path) ast.Node
- func DereferenceAll(root ast.Node, path protopath.Path) []ast.Node
- func Join[T protopath.Step, S ~[]T](a protopath.Path, b S) protopath.Path
- func NodeAt[T ast.Node](idx PathIndex) (t T)
- func NodeIsConcrete(values protopath.Values, index int) bool
- func NodeView(in func(v ast.Node)) func(v protopath.Values) error
- func Slice(from protopath.Values, start, end int) protopath.Values
- func Suffix2[T, U ast.Node](values protopath.Values) (out struct{ ... }, ok bool)
- func Suffix3[T, U, V ast.Node](values protopath.Values) (out struct{ ... }, ok bool)
- func Suffix4[T, U, V, W ast.Node](values protopath.Values) (out struct{ ... }, ok bool)
- func Suffix5[T, U, V, W, X ast.Node](values protopath.Values) (out struct{ ... }, ok bool)
- func ValuesToNodes(values protopath.Values) (nodes []ast.Node)
- type AncestorTracker
- type PathIndex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dereference ¶
Dereference walks the given path from the root node and returns the node at the end of the path.
func DereferenceAll ¶
DereferenceAll walks the given path from the root node and returns all nodes visited. The first node in the returned slice is the root node. Not all path steps reference an actual node in the AST, so the returned slice may contain fewer than len(path) nodes.
func Join ¶
Join returns a new path constructed by appending the steps of 'b' to 'a'. The first step in 'b' is skipped; it is assumed (but not checked for) that 'b' starts with a Root step matching the message type of the last step in path 'a'.
func NodeIsConcrete ¶
NodeIsConcrete returns true if the value at the given index in 'values' is a concrete node value, and false otherwise. A concrete node is a message that is not a wrapper node (or an array access to a wrapper node), and is not a list or map.
func NodeView ¶
NodeView returns a visitor suitable for use with ast.WithBefore and ast.WithAfter which calls the given function for each concrete node value encountered, ignoring wrapper nodes and other non-node values.
func Slice ¶
Slice returns a new path with both its path and values resliced by the given range. It is assumed that both slices are of the same length.
func Suffix2 ¶
func Suffix2[T, U ast.Node](values protopath.Values) ( out struct { T T TIndex int U U UIndex int }, ok bool, )
Suffix2 inspects the given values and, if the path logically ends with the sequence of nodes 'T, U' (such that U is a message field of T), returns the two nodes and true. Otherwise, returns false. This method correctly handles non-node path steps such as list accesses. The returned nodes may not necessarily be the final 2 nodes in the path.
Types ¶
type AncestorTracker ¶
type AncestorTracker struct {
// contains filtered or unexported fields
}
AncestorTracker is used to track the path of nodes during a walk operation. By passing AsWalkOptions to a call to Walk, a visitor can inspect the path to the node being visited using this tracker.
func (*AncestorTracker) AsWalkOptions ¶
func (t *AncestorTracker) AsWalkOptions() []ast.WalkOption
AsWalkOptions returns WalkOption values that will cause this ancestor tracker to track the path through the AST during the walk operation.
func (*AncestorTracker) Path ¶
func (t *AncestorTracker) Path() protopath.Path
Path returns a slice of nodes that represents the path from the root of the walk operaiton to the currently visited node. The first element in the path is the root supplied to Walk. The last element in the path is the currently visited node.
func (*AncestorTracker) Values ¶
func (t *AncestorTracker) Values() protopath.Values
Values returns a copy of the tracked path and values at the currently visited node.