parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package parser provides interfaces and implementations for extracting import dependencies and exported symbols from source files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Import added in v0.5.0

type Import struct {
	Path string
	Kind ImportKind
}

Import is a raw import path with its kind.

type ImportKind added in v0.5.0

type ImportKind int

ImportKind classifies an import statement.

const (
	ImportDefault  ImportKind = iota
	ImportTypeOnly            // e.g., TypeScript "import type"
)

type Parser

type Parser interface {
	// Language returns the language name (e.g., "go", "typescript", "python").
	Language() string

	// Extensions returns file extensions this parser handles (e.g., ".go", ".ts").
	Extensions() []string

	// ParseImports returns the raw import paths found in the file.
	ParseImports(filePath string) ([]Import, error)

	// ParseSymbols returns exported symbols from the file.
	// May return nil if the parser doesn't support symbol extraction.
	ParseSymbols(filePath string) ([]Symbol, error)
}

Parser extracts import/dependency edges from a source file.

type Registry

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

Registry holds parsers keyed by extension and language.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a registry with tree-sitter parsers for all supported languages.

func NewRegistry

func NewRegistry(parsers ...Parser) *Registry

NewRegistry creates a registry from the given parsers.

func (*Registry) ForExtension

func (r *Registry) ForExtension(ext string) Parser

ForExtension returns the parser registered for the given extension, or nil.

func (*Registry) ForLanguage

func (r *Registry) ForLanguage(lang string) Parser

ForLanguage returns the parser registered for the given language name, or nil.

func (*Registry) Languages

func (r *Registry) Languages() []string

Languages returns all registered language names.

func (*Registry) RegisteredExtensions

func (r *Registry) RegisteredExtensions() []string

RegisteredExtensions returns all file extensions the registry handles.

type Symbol added in v0.5.0

type Symbol struct {
	Name string
	Kind SymbolKind
}

Symbol is an exported identifier with its kind.

type SymbolKind added in v0.5.0

type SymbolKind int

SymbolKind classifies a symbol extracted from source code.

const (
	SymbolUnknown   SymbolKind = iota
	SymbolFunction             // functions, methods
	SymbolType                 // classes, structs, type aliases
	SymbolConstant             // constants, enum values
	SymbolVariable             // exported variables
	SymbolInterface            // interfaces, traits, protocols
)

type TreeSitterParser

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

TreeSitterParser extracts imports and symbols using tree-sitter grammars.

func (*TreeSitterParser) Extensions

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

func (*TreeSitterParser) Language

func (p *TreeSitterParser) Language() string

func (*TreeSitterParser) ParseImports

func (p *TreeSitterParser) ParseImports(filePath string) ([]Import, error)

func (*TreeSitterParser) ParseSymbols

func (p *TreeSitterParser) ParseSymbols(filePath string) ([]Symbol, error)

Jump to

Keyboard shortcuts

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