go: cuelang.org/go/cue/ast/astutil Index | Files

package astutil

import "cuelang.org/go/cue/ast/astutil"

Index

Package Files

apply.go resolve.go util.go walk.go

func Apply Uses

func Apply(node ast.Node, before, after func(Cursor) bool) ast.Node

Apply traverses a syntax tree recursively, starting with root, and calling pre and post for each node as described below. Apply returns the syntax tree, possibly modified.

If pre is not nil, it is called for each node before the node's children are traversed (pre-order). If pre returns false, no children are traversed, and post is not called for that node.

If post is not nil, and a prior call of pre didn't return false, post is called for each node after its children are traversed (post-order). If post returns false, traversal is terminated and Apply returns immediately.

Only fields that refer to AST nodes are considered children; i.e., token.Pos, Scopes, Objects, and fields of basic types (strings, etc.) are ignored.

Children are traversed in the order in which they appear in the respective node's struct definition.

func ApplyRecursively Uses

func ApplyRecursively(n ast.Node) ast.Node

ApplyRecursively indicates that a node inserted with InsertBefore, or InsertAfter should be processed recursively.

func CopyComments Uses

func CopyComments(to, from ast.Node)

CopyComments associates comments of one node with another. It may change the relative position of comments.

func CopyMeta Uses

func CopyMeta(to, from ast.Node) ast.Node

CopyMeta copies comments and position information from one node to another. It returns the destination node.

func CopyPosition Uses

func CopyPosition(to, from ast.Node)

CopyPosition sets the position of one node to another.

func Resolve Uses

func Resolve(f *ast.File, errFn ErrFunc)

Resolve resolves all identifiers in a file. Unresolved identifiers are recorded in Unresolved. It will not overwrite already resolved values.

func ResolveExpr Uses

func ResolveExpr(e ast.Expr, errFn ErrFunc)

Resolve resolves all identifiers in an expression. It will not overwrite already resolved values.

type Cursor Uses

type Cursor interface {
    // Node returns the current Node.
    Node() ast.Node

    // Parent returns the parent of the current Node.
    Parent() Cursor

    // Index reports the index >= 0 of the current Node in the slice of Nodes
    // that contains it, or a value < 0 if the current Node is not part of a
    // list.
    Index() int

    // Import reports an opaque identifier that refers to the given package. It
    // may only be called if the input to apply was an ast.File. If the import
    // does not exist, it will be added.
    Import(path string) *ast.Ident

    // Replace replaces the current Node with n.
    // The replacement node is not walked by Apply. Comments of the old node
    // are copied to the new node if it has not yet an comments associated
    // with it.
    Replace(n ast.Node)

    // Delete deletes the current Node from its containing struct.
    // If the current Node is not part of a struct, Delete panics.
    Delete()

    // InsertAfter inserts n after the current Node in its containing struct.
    // If the current Node is not part of a struct, InsertAfter panics.
    // Unless n is wrapped by ApplyRecursively, Apply does not walk n.
    InsertAfter(n ast.Node)

    // InsertBefore inserts n before the current Node in its containing struct.
    // If the current Node is not part of a struct, InsertBefore panics.
    // Unless n is wrapped by ApplyRecursively, Apply does not walk n.
    InsertBefore(n ast.Node)
    // contains filtered or unexported methods
}

A Cursor describes a node encountered during Apply. Information about the node and its parent is available from the Node, Parent, and Index methods.

The methods Replace, Delete, InsertBefore, and InsertAfter can be used to change the AST without disrupting Apply. Delete, InsertBefore, and InsertAfter are only defined for modifying a StructLit and will panic in any other context.

type ErrFunc Uses

type ErrFunc func(pos token.Pos, msg string, args ...interface{})

An ErrFunc processes errors.

Package astutil imports 10 packages (graph) and is imported by 7 packages. Updated 2019-12-09. Refresh now. Tools for package owners.