parse

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package parse turns source files into language-neutral symbol and reference facts. One Extractor per language; the indexer stays free of language knowledge.

Extraction is deliberately syntactic: call references are recorded as (qualifier, name) pairs and resolved to symbols later by the indexer with declared confidence (model.Origin*). Type-accurate resolution is a future refinement, not a prerequisite — the graph records how each edge was derived so consumers can filter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FamilyForPath

func FamilyForPath(p string) string

FamilyForPath returns the language family for a file path by extension, "" when unsupported. Kept in sync with the extractors' Extensions() — static so read-only surfaces can classify paths without instantiating parsers.

func LanguageFamily

func LanguageFamily(lang string) string

LanguageFamily groups languages that share one symbol namespace: the three ECMA dialects (JS, TS, TSX) import each other freely and must be resolved as a single family; every other language is its own.

Types

type CallRef

type CallRef struct {
	// Qualifier is the identifier the call is selected from: "pkg" in
	// pkg.F(), "w" in w.Run(). Empty for bare calls and for selector calls
	// whose operand is a complex expression (x.db.Close(), f().Close()).
	Qualifier string
	Name      string // called identifier / method name
	Line      uint32 // 1-based
	// Selector distinguishes x.F() from F(). Bare calls resolve against
	// package-level functions; selector calls must never be, even when
	// Qualifier is empty — the operand is a value, not the package scope.
	Selector bool
	// Receiver marks a call through the enclosing method's own receiver —
	// Python's first parameter, Go's named receiver, JS/TS's lexical
	// `this`. Set by the extractor from the declaration, never inferred
	// from spelling: a local variable named "self" must not qualify.
	Receiver bool
}

CallRef is an unresolved call site inside a declaration.

type EcmaDialect

type EcmaDialect string

EcmaDialect selects the grammar variant of the ECMAScript-family extractor. TSX needs its own grammar; plain JS handles JSX natively.

const (
	EcmaJS  EcmaDialect = "javascript"
	EcmaTS  EcmaDialect = "typescript"
	EcmaTSX EcmaDialect = "tsx"
)

The supported dialects.

type EcmaExtractor

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

EcmaExtractor extracts symbols, imports, and call references from JavaScript and TypeScript files. Unlike Go, the ES module system scopes per file: the package key is the repo-relative path without extension, and relative imports are resolved here (the extractor knows the file's location; the indexer does not know ES resolution rules).

func NewEcmaExtractor

func NewEcmaExtractor(dialect EcmaDialect) (*EcmaExtractor, error)

NewEcmaExtractor compiles the queries for one dialect.

func (*EcmaExtractor) Close

func (e *EcmaExtractor) Close()

Close releases the underlying parser and queries.

func (*EcmaExtractor) Extensions

func (e *EcmaExtractor) Extensions() []string

Extensions lists the file extensions routed to this extractor.

func (*EcmaExtractor) Extract

func (e *EcmaExtractor) Extract(relPath string, src []byte) (*FileResult, error)

Extract parses one JS/TS file. The package key is the file's module path: repo-relative, extension stripped ("web/src/api/client").

func (*EcmaExtractor) Language

func (e *EcmaExtractor) Language() string

Language returns the registry key for this dialect.

type Extractor

type Extractor interface {
	Language() string
	Extensions() []string // with leading dot, e.g. ".go"
	// Extract parses src of the file at repo-relative relPath.
	Extract(relPath string, src []byte) (*FileResult, error)
	Close()
}

Extractor parses one language. Implementations are not safe for concurrent use; the indexer runs one goroutine per Extractor instance.

type FileResult

type FileResult struct {
	Path     string // repo-relative
	Language string
	Package  string // repo-relative package/module key (directory for Go)
	Symbols  []SymbolDecl
	Imports  []Import
}

FileResult is everything extracted from one file.

type GoExtractor

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

GoExtractor extracts symbols, imports, and call references from Go files.

func NewGoExtractor

func NewGoExtractor() (*GoExtractor, error)

NewGoExtractor compiles the tree-sitter queries for Go.

func (*GoExtractor) Close

func (g *GoExtractor) Close()

Close releases the underlying parser and queries.

func (*GoExtractor) Extensions

func (g *GoExtractor) Extensions() []string

Extensions lists the file extensions routed to this extractor.

func (*GoExtractor) Extract

func (g *GoExtractor) Extract(relPath string, src []byte) (*FileResult, error)

Extract parses one Go file. The package key is the file's repo-relative directory ("" at the repo root), which keeps FQNs stable across module renames and readable in output: "internal/store.Store.UpsertSymbols".

func (*GoExtractor) Language

func (g *GoExtractor) Language() string

Language returns the registry key for Go.

type Import

type Import struct {
	Path string // as written, e.g. "github.com/spf13/cobra" or "./api/client"
	// LocalName is the identifier that qualifies member calls through this
	// import: the Go package alias, or a JS/TS namespace import (`* as ns`).
	// "" when the import contributes no qualifier.
	LocalName string
	// Named lists identifiers imported un-aliased into the file's scope
	// (`import {foo} from …`). Bare calls to these resolve into the
	// imported module. Aliased imports are omitted — their local names
	// cannot be looked up in the target module. Unused by Go.
	Named []string
	// Resolved is the repo-relative package/module key this import points
	// at, when the extractor can resolve it by itself (JS/TS relative
	// specifiers). "" means the indexer decides (Go module paths) or the
	// import is external.
	Resolved string
}

Import is one import clause of a file.

type PyExtractor

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

PyExtractor extracts symbols, imports, and call references from Python files. Python modules scope per file, like ES modules: the package key is the repo-relative path without ".py", and "pkg/__init__.py" collapses to "pkg" — the module Python itself calls pkg.

func NewPyExtractor

func NewPyExtractor() (*PyExtractor, error)

NewPyExtractor compiles the tree-sitter queries for Python.

func (*PyExtractor) Close

func (p *PyExtractor) Close()

Close releases the underlying parser and queries.

func (*PyExtractor) Extensions

func (p *PyExtractor) Extensions() []string

Extensions lists the file extensions routed to this extractor.

func (*PyExtractor) Extract

func (p *PyExtractor) Extract(relPath string, src []byte) (*FileResult, error)

Extract parses one Python file.

func (*PyExtractor) Language

func (p *PyExtractor) Language() string

Language returns the registry key for Python.

type Registry

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

Registry maps file extensions to extractors.

func NewRegistry

func NewRegistry() (*Registry, error)

NewRegistry constructs all built-in extractors.

func (*Registry) Close

func (r *Registry) Close()

Close releases parser resources.

func (*Registry) ForPath

func (r *Registry) ForPath(path string) Extractor

ForPath returns the extractor handling path, or nil when unsupported.

type SymbolDecl

type SymbolDecl struct {
	Symbol model.Symbol
	Calls  []CallRef
}

SymbolDecl is a declared symbol plus the call references inside its body.

Jump to

Keyboard shortcuts

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