astquery

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package astquery is a structural (AST-shape) search over Go source with metavariables — the "match code by shape, not text" seam (#3438, epic #3434). It is the semgrep/comby idea in miniature: a pattern is a fragment of Go with $NAME holes, and it matches any subtree of the same shape, binding each hole to the concrete node it lands on. A repeated hole must bind consistently, so `$X == $X` matches `a == a` but not `a == b` — the property a plain regex or the trigram index (#3437) cannot express.

Scope is expression patterns: the pattern parses as a Go expression, and every expression subtree of the target file is a candidate. That already covers the high-value queries (call shapes, comparisons, selector chains) and keeps the matcher a small, total tree-unification over the go/ast node types it knows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComparisonArm added in v0.44.0

type ComparisonArm struct {
	Name            string
	Kind            string
	Available       bool
	Correct         bool
	Latency         time.Duration
	TruePositives   int
	FalsePositives  int
	FalseNegatives  int
	BindingErrors   int
	LocationErrors  int
	ParseFailures   int
	InputBytes      int64
	CPUSeconds      float64
	PeakRSSBytes    int64
	NetworkBytes    int64
	OperatorSeconds float64
	CostUSD         float64
	Note            string
}

type ComparisonResult added in v0.44.0

type ComparisonResult struct {
	Workload string
	Arms     []ComparisonArm
}

func CompareLocal added in v0.44.0

func CompareLocal() ComparisonResult

type Match

type Match struct {
	Pos      token.Position
	Text     string
	Bindings map[string]string
}

Match is one structural hit: the source position of the matched subtree and the metavariable bindings that made it match (rendered back to source text).

func Search(src, pattern string) ([]Match, error)

Search parses src (a full Go file) and returns every expression subtree matching pattern, with bindings. Matches are returned in source order.

Jump to

Keyboard shortcuts

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