Documentation
¶
Overview ¶
Package analysis provides scope-aware semantic analysis for ELPS lisp source.
The analyzer builds a scope tree from parsed expressions, resolves symbol references, and identifies unresolved symbols. It is designed to be used by lint analyzers for semantic checks like undefined-symbol and unused-variable.
Index ¶
- func ExtractPackageExports(reg *lisp.PackageRegistry) map[string][]ExternalSymbol
- func ScanWorkspacePackages(root string) (map[string][]ExternalSymbol, error)
- type Config
- type ExternalSymbol
- type Reference
- type Result
- type Scope
- type ScopeKind
- type Signature
- type Symbol
- type SymbolKind
- type UnresolvedRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPackageExports ¶
func ExtractPackageExports(reg *lisp.PackageRegistry) map[string][]ExternalSymbol
ExtractPackageExports creates a map of package name to exported symbols from a loaded runtime's package registry. This is used to resolve use-package imports for packages defined in Go (stdlib) that cannot be found by workspace scanning.
func ScanWorkspacePackages ¶
func ScanWorkspacePackages(root string) (map[string][]ExternalSymbol, error)
ScanWorkspacePackages is like ScanWorkspace but returns a map of package name to exported symbols, suitable for use as Config.PackageExports.
Types ¶
type Config ¶
type Config struct {
// ExtraGlobals are symbols from other files (e.g. workspace scanning).
ExtraGlobals []ExternalSymbol
// PackageExports maps package names to their exported symbols.
// Used to resolve use-package imports from stdlib and workspace packages.
PackageExports map[string][]ExternalSymbol
// Filename is the source file being analyzed.
Filename string
}
Config controls the behavior of the analyzer.
type ExternalSymbol ¶
type ExternalSymbol struct {
Name string
Kind SymbolKind
Package string
Signature *Signature
Source *token.Location
DocString string
}
ExternalSymbol represents a symbol defined in another file.
func ScanWorkspace ¶
func ScanWorkspace(root string) ([]ExternalSymbol, error)
ScanWorkspace walks a directory tree, parsing all .lisp files and extracting exported top-level definitions. The result can be used as Config.ExtraGlobals for cross-file symbol resolution.
Files that fail to parse are silently skipped (fault tolerant).
func ScanWorkspaceFull ¶ added in v1.27.0
func ScanWorkspaceFull(root string) ([]ExternalSymbol, map[string][]ExternalSymbol, error)
ScanWorkspaceFull walks a directory tree in a single pass, parsing all .lisp files and extracting both global symbols and package exports. It skips hidden directories (names starting with '.') and node_modules.
Files that fail to parse are silently skipped (fault tolerant).
type Result ¶
type Result struct {
RootScope *Scope
Symbols []*Symbol
References []*Reference
Unresolved []*UnresolvedRef
}
Result holds the output of semantic analysis.
type Scope ¶
type Scope struct {
Kind ScopeKind
Parent *Scope
Children []*Scope
Symbols map[string]*Symbol
Node *lisp.LVal // the AST node that introduced this scope
}
Scope represents a lexical scope in the source.
func (*Scope) Lookup ¶
Lookup resolves a symbol by walking the parent chain. Returns nil if the symbol is not found.
func (*Scope) LookupLocal ¶
LookupLocal resolves a symbol only in this scope (not parents).
type Signature ¶
Signature describes the parameter signature of a callable symbol.
type Symbol ¶
type Symbol struct {
Name string
Kind SymbolKind
Source *token.Location // nil for builtins
Scope *Scope
Signature *Signature // non-nil for callables
DocString string
References int
Exported bool
External bool // true for workspace-scanned or package-imported symbols
}
Symbol represents a defined name in a scope.
type SymbolKind ¶
type SymbolKind int
SymbolKind classifies a symbol definition.
const ( SymVariable SymbolKind = iota // set, let binding SymFunction // defun, flet/labels binding SymMacro // defmacro SymParameter // function/lambda parameter SymSpecialOp // special operator (if, cond, etc.) SymBuiltin // builtin function SymType // deftype )
func (SymbolKind) String ¶
func (k SymbolKind) String() string