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

parse

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	KindFile      = "file"
	KindPackage   = "package"
	KindModule    = "module"
	KindFunction  = "function"
	KindMethod    = "method"
	KindType      = "type"
	KindImport    = "import"
	KindSymbol    = "symbol"
	KindOperation = "operation"
	KindSchema    = "schema"
	KindField     = "field"
	KindService   = "service"
	KindDoc       = "doc"     // Markdown / ADR document node (Phase 3)
	KindHeading   = "heading" // Doc section heading (Phase 3)
)

Node kinds emitted by extractors and contract parsers.

View Source
const (
	EdgeContains   graph.EdgeType = "contains"
	EdgeImports    graph.EdgeType = "imports"
	EdgeCalls      graph.EdgeType = "calls"
	EdgeImplements graph.EdgeType = "implements"
	EdgeConsumes   graph.EdgeType = "consumes"
	// Phase 3 semantic edge families (SYN-3).
	EdgeCoCommitted   graph.EdgeType = "co_committed"   // git history co-change (HISTORICAL)
	EdgeObservedCalls graph.EdgeType = "observed_calls" // OpenTelemetry runtime calls (OBSERVED)
	EdgeDocuments     graph.EdgeType = "documents"      // doc → symbol / path reference
)

Edge types emitted by extractors and contract binders.

View Source
const (
	PropProvenance = "provenance"
	PropWeight     = "weight"
	PropSupport    = "support"
	PropCount      = "count"
	PropLastSeen   = "last_seen"
	PropDoc        = "doc" // godoc / TSDoc / JSDoc text on a symbol node

	ProvenanceExtracted  = "EXTRACTED"
	ProvenanceInferred   = "INFERRED"
	ProvenanceHistorical = "HISTORICAL"
	ProvenanceObserved   = "OBSERVED"
)

Edge property keys and provenance values for Phase 3 edges.

Variables

View Source
var DefaultIgnoreDirNames = []string{"vendor", "node_modules", ".git", ".synapse", ".synapse-out"}

DefaultIgnoreDirNames are skipped unless overridden.

Functions

func EnsureRootExists

func EnsureRootExists(root string) error

EnsureRootExists is a tiny helper for clearer Walk errors.

func ListSourceFiles

func ListSourceFiles(root string, reg *Registry, ignoreDirNames []string) ([]string, error)

ListSourceFiles returns registered source paths under root (sync, for tests).

Types

type Extractor

type Extractor func(path string, src []byte, root *tree_sitter.Node) Result

Extractor turns a parsed tree into graph IR.

type Language

type Language struct {
	Name     string
	Language *tree_sitter.Language
	Extract  Extractor
}

Language is a registered grammar keyed by file extension.

type Registry

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

Registry maps file extensions (with leading dot, lower-case) to languages.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a registry with Go, JS/JSX, TypeScript/TSX, Python, Swift, Java, Kotlin, Ruby, PHP, C, C++, and C#.

func (*Registry) Lookup

func (r *Registry) Lookup(path string) *Language

Lookup returns the language for path's extension, or nil if unknown.

func (*Registry) Register

func (r *Registry) Register(ext string, lang *Language)

Register associates an extension with a language. ext may be ".go" or "go".

type Result

type Result struct {
	Path    string       `json:"path"`
	Lang    string       `json:"lang"`
	Nodes   []graph.Node `json:"nodes"`
	Edges   []graph.Edge `json:"edges"`
	Skipped bool         `json:"skipped,omitempty"`
}

Result is the intermediate Node/Edge IR for one source file.

func ParseFile

func ParseFile(reg *Registry, path string) (Result, error)

ParseFile reads path and extracts IR using reg. Unknown extensions yield Skipped=true.

func ParseSource

func ParseSource(reg *Registry, path string, src []byte) (Result, error)

ParseSource parses src as path using reg.

func ParseTree

func ParseTree(path string, src []byte, root *tree_sitter.Node, extract Extractor) Result

ParseTree is a helper for tests that already have a root node.

func (*Result) Normalize

func (r *Result) Normalize()

Normalize sorts nodes and edges for deterministic golden comparisons.

type WalkOptions

type WalkOptions struct {
	// IgnoreDirNames are directory basenames to skip (default: vendor, node_modules, .git, .synapse).
	IgnoreDirNames []string
	// Workers is the concurrent parse pool size (default: GOMAXPROCS).
	Workers int
	// Registry selects parsers; nil uses NewRegistry().
	Registry *Registry
}

WalkOptions configures repository walking.

type WalkResult

type WalkResult struct {
	Results []Result
	Errors  []error
}

WalkResult aggregates per-file parse results and errors.

func WalkTree

func WalkTree(root string, opts WalkOptions) (WalkResult, error)

WalkTree walks root, skipping ignored dirs, and parses registered source files concurrently.

Jump to

Keyboard shortcuts

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