parse

package
v0.0.0-...-cbea048 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 15 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"
)

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"
)

Edge types emitted by extractors and contract binders.

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, and Swift.

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