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

traverse

package
v0.57.21 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBreak = errors.New("BREAK")

ErrBreak will terminate visit execution returning a nil error.

View Source
var ErrContinue = errors.New("CONTINUE")

ErrContinue will skip the node and its children.

Functions

func Visit

func Visit(
	ctx context.Context,
	blk block.Block,
	bcs *block.Cursor,
	cb Visitor,
	existingOnly bool,
) error

Visit will walk through a block tree using a depth-first traversal. The callback is called with each block in the tree.

If existingOnly, only returns references that have already been traversed. If !existingOnly uses GetSubBlocks and/or GetBlockRefs to list all references.

Types

type Location

type Location struct {
	// Depth is the depth of this position.
	Depth int
	// Parent contains the parent location.
	Parent *Location
	// Cursor contains the block graph cursor at the location.
	Cursor *block.Cursor
	// Block contains the block or sub-block at the location.
	// May be nil if the block type is unknown or ref not found.
	Block any
	// ParentRefID is the reference ID that was previously followed.
	ParentRefID uint32
}

Location is a position in the visitor graph

func (*Location) GetParentBlocks

func (l *Location) GetParentBlocks() []any

GetParentBlocks traverses the list and gets all parent blocks The tail block is the first in the list.

type Visitor

type Visitor func(*Location) error

Visitor is the callback for visiting a block graph. Returning a non-nil error will end execution. Returning ErrBreak will end execution returning a nil error.

Jump to

Keyboard shortcuts

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