ast

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NodeHandler

type NodeHandler func(node ast.Node, path []ast.Node)

NodeHandler defines a function that handles a specific AST node.

type ParsedFile

type ParsedFile struct {
	File   *ast.File      // Parsed AST
	Fset   *token.FileSet // FileSet for position mapping
	Path   string         // Absolute file path
	Source []byte         // Raw source code (optional)
}

ParsedFile represents a parsed Go source file with its AST and FileSet.

func ParseFile

func ParseFile(path string) (*ParsedFile, error)

ParseFile parses a Go source file into an AST with a new FileSet.

func ParseSource

func ParseSource(path string, src []byte) (*ParsedFile, error)

ParseSource parses the provided Go source code (in-memory) with a new FileSet.

type Walker

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

Walker allows walking through the AST with custom handlers per node type.

func NewWalker

func NewWalker(fset *token.FileSet) *Walker

NewWalker creates a new AST walker.

func (*Walker) RegisterHandler

func (w *Walker) RegisterHandler(nodeType string, handler NodeHandler)

RegisterHandler registers a handler for the given node type (e.g. *ast.CallExpr).

func (*Walker) WalkFile

func (w *Walker) WalkFile(file *ast.File)

WalkFile walks the AST of the given file.

Jump to

Keyboard shortcuts

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