goast

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package goast reads Go source with go/ast and returns a stage-1 code graph.

Provenance

The walk, the node-id scheme and the type and call resolution below are a copy of analyzers/go/goscan.go from the working tree this project was developed alongside, recognisable line by line. The output layer and the diagnostics block are new: the original counted parse errors, and this records each one with its path and line, because a count cannot be acted on.

That file is the author's own rather than the reference project's. It does not exist on that project's origin/main and every commit touching it is the author's, so no attribution is owed. It is said here anyway: a reader of eleven hundred lines should not have to find a licensing document to learn that most of them came from somewhere else. See THIRD_PARTY_NOTICES.md and docs/licensing.md.

Only the standard library is used. An analyzer that needed `go get` would break the self-contained binary this project is built around, and go/ast is always current with the compiler that builds it, so a Go 1.27 build understands Go 1.27 on the day it ships.

That is also why tree-sitter is not used for Go, though it is used for the other languages. The tree-sitter Go grammar's method_declaration rule carries no type parameters, so a generic method does not parse; and tree-sitter fails soft, emitting an ERROR node and continuing, so the method would simply be missing from the graph with nothing to say it was ever there. No later stage can restore what was never extracted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Analyze

func Analyze(ctx context.Context, root string, opts Options) (*graph.Graph, error)

Analyze walks root and returns what go/ast could prove about it.

The returned graph is sorted and therefore byte-identical across runs of the same binary over the same source. Files that fail to parse are recorded in Diagnostics rather than dropped, because a missing declaration and a declaration that was never written look identical once the graph is written.

Types

type Analyzer

type Analyzer struct{}

Analyzer reads Go source. The zero value is ready to use.

func (Analyzer) Analyze

func (Analyzer) Analyze(ctx context.Context, root string, opts analyze.Options) (*graph.Graph, error)

Analyze satisfies analyze.Analyzer.

func (Analyzer) Extensions

func (Analyzer) Extensions() []string

Extensions lists the suffixes it claims.

func (Analyzer) Language

func (Analyzer) Language() graph.Language

Language names what this analyzer reads.

type Options

type Options analyze.Options

Options tunes a walk. It mirrors analyze.Options so this package can be used directly without importing the interface it satisfies.

Jump to

Keyboard shortcuts

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