parser

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLanguageFromExtension

func GetLanguageFromExtension(ext string) string

GetLanguageFromExtension returns the language name for a given file extension

func LanguageFromExtension

func LanguageFromExtension(ext string) string

LanguageFromExtension maps file extension to language name

func ReleaseExtractor

func ReleaseExtractor(ue *UnifiedExtractor)

ReleaseExtractor returns an extractor to the pool after resetting its state The slices are cleared but retain their capacity for reuse

func ReleaseParser

func ReleaseParser(p *TreeSitterParser)

ReleaseParser returns a parser to the pool for reuse This must be called when done with the parser

func ReleaseParserToPool

func ReleaseParserToPool(p *TreeSitterParser, language Language)

ReleaseParserToPool returns a parser to its language-specific pool Call this when done with a language-specific parser

Types

type AwaitInfo

type AwaitInfo struct {
	Line        int
	AssignedVar string
	CallTarget  string
	UsedVars    []string
}

AwaitInfo exported for use by performance analyzer

type BlockBoundary

type BlockBoundary struct {
	Start int
	End   int
	Type  BlockType
	Name  string
	Depth int
}

type BlockType

type BlockType uint8
const (
	BlockTypeFunction BlockType = iota
	BlockTypeClass
	BlockTypeMethod
	BlockTypeInterface
	BlockTypeStruct
	BlockTypeBlock
)

func (BlockType) String

func (b BlockType) String() string

type CallInfo

type CallInfo struct {
	Target    string
	Line      int
	InLoop    bool
	LoopDepth int
	LoopLine  int
}

CallInfo exported for use by performance analyzer

type CommunityParserAdapter

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

CommunityParserAdapter provides a standardized interface for community parsers

func NewCommunityParserAdapter

func NewCommunityParserAdapter(name string, extensions []string, getLanguage func() *tree_sitter.Language, queryDef string) *CommunityParserAdapter

NewCommunityParserAdapter creates a new adapter for community parsers

func (*CommunityParserAdapter) Extensions

func (cpa *CommunityParserAdapter) Extensions() []string

Extensions returns supported file extensions

func (*CommunityParserAdapter) GetLanguage

func (cpa *CommunityParserAdapter) GetLanguage() *tree_sitter.Language

GetLanguage returns the tree-sitter language

func (*CommunityParserAdapter) GetQueryDefinition

func (cpa *CommunityParserAdapter) GetQueryDefinition() string

GetQueryDefinition returns the tree-sitter query string

func (*CommunityParserAdapter) Name

func (cpa *CommunityParserAdapter) Name() string

Name returns the parser name

func (*CommunityParserAdapter) SetupParser

func (cpa *CommunityParserAdapter) SetupParser(p *TreeSitterParser) error

SetupParser configures a parser instance with this community parser

type CommunityParserRegistry

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

CommunityParserRegistry manages all community parser adapters

func NewCommunityParserRegistry

func NewCommunityParserRegistry() *CommunityParserRegistry

NewCommunityParserRegistry creates a new registry

func (*CommunityParserRegistry) GetAdapter

func (cpr *CommunityParserRegistry) GetAdapter(name string) (*CommunityParserAdapter, bool)

GetAdapter retrieves a community parser adapter by name

func (*CommunityParserRegistry) GetAdapterForExtension

func (cpr *CommunityParserRegistry) GetAdapterForExtension(ext string) (*CommunityParserAdapter, bool)

GetAdapterForExtension finds the appropriate adapter for a file extension

func (*CommunityParserRegistry) ListAdapters

func (cpr *CommunityParserRegistry) ListAdapters() []string

ListAdapters returns all registered adapter names

func (*CommunityParserRegistry) Register

func (cpr *CommunityParserRegistry) Register(adapter *CommunityParserAdapter)

Register adds a community parser adapter to the registry

func (*CommunityParserRegistry) SetupAllParsers

func (cpr *CommunityParserRegistry) SetupAllParsers(p *TreeSitterParser) []error

SetupAllParsers configures all registered community parsers on a TreeSitterParser instance

type DeclarationInfo

type DeclarationInfo struct {
	Signature  string
	DocComment string
}

DeclarationInfo stores extracted metadata for a declaration

type DeclarationLookup

type DeclarationLookup interface {
	// Lookup retrieves signature and doc comment for a symbol at given position (1-based line/column)
	Lookup(line, column int) (signature string, docComment string)
}

DeclarationLookup is an interface for looking up declaration metadata. UnifiedExtractor implements this interface.

type Language

type Language string

Language represents the programming language for parser selection

const (
	LanguageGo         Language = "go"
	LanguagePython     Language = "python"
	LanguageJavaScript Language = "javascript"
	LanguageTypeScript Language = "typescript"
	LanguageRust       Language = "rust"
	LanguageJava       Language = "java"
	LanguageCpp        Language = "cpp"
	LanguageCSharp     Language = "csharp"
	LanguageZig        Language = "zig"
	LanguagePHP        Language = "php"
)

type LoopInfo

type LoopInfo struct {
	NodeType  string
	StartLine int
	EndLine   int
	Depth     int
}

LoopInfo exported for use by performance analyzer

type PerfAnalysisResult

type PerfAnalysisResult struct {
	FunctionName string
	StartLine    int
	EndLine      int
	IsAsync      bool
	Language     string
	FilePath     string
	Loops        []LoopInfo
	Awaits       []AwaitInfo
	Calls        []CallInfo
}

PerfAnalysisResult holds performance analysis for a function

type PositionKey

type PositionKey struct {
	Line   int
	Column int
}

PositionKey is a zero-allocation key type for line:column lookups Replaces fmt.Sprintf("%d:%d") which allocates ~500KB per 1000 symbols

type SideEffectTracker

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

SideEffectTracker integrates side effect analysis into AST extraction. It hooks into the UnifiedExtractor to track accesses and function calls during the AST traversal, enabling accurate side effect detection.

func NewSideEffectTracker

func NewSideEffectTracker(language string) *SideEffectTracker

NewSideEffectTracker creates a new tracker for the given language

func (*SideEffectTracker) AddLocalVariable

func (st *SideEffectTracker) AddLocalVariable(name string, line int)

AddLocalVariable registers a local variable

func (*SideEffectTracker) AddParameter

func (st *SideEffectTracker) AddParameter(name string, index int)

AddParameter registers a function parameter

func (*SideEffectTracker) BeginFunction

func (st *SideEffectTracker) BeginFunction(name, file string, startLine, endLine int)

BeginFunction starts tracking a new function

func (*SideEffectTracker) EndFunction

func (st *SideEffectTracker) EndFunction() *types.SideEffectInfo

EndFunction completes tracking of the current function

func (*SideEffectTracker) GetAnalyzer

func (st *SideEffectTracker) GetAnalyzer() *analysis.SideEffectAnalyzer

GetAnalyzer returns the underlying analyzer (for direct access if needed)

func (*SideEffectTracker) GetResults

func (st *SideEffectTracker) GetResults() map[string]*types.SideEffectInfo

GetResults returns all analysis results

func (*SideEffectTracker) IsInFunction

func (st *SideEffectTracker) IsInFunction() bool

IsInFunction returns whether we're currently tracking a function

func (*SideEffectTracker) ProcessAssignment

func (st *SideEffectTracker) ProcessAssignment(node *tree_sitter.Node, content []byte, getNodeType func(*tree_sitter.Node) string)

ProcessAssignment handles an assignment expression/statement

func (*SideEffectTracker) ProcessChannelOp

func (st *SideEffectTracker) ProcessChannelOp(line int)

ProcessChannelOp handles a channel send/receive (Go)

func (*SideEffectTracker) ProcessDefer

func (st *SideEffectTracker) ProcessDefer()

ProcessDefer handles a defer statement (Go)

func (*SideEffectTracker) ProcessFunctionCall

func (st *SideEffectTracker) ProcessFunctionCall(node *tree_sitter.Node, content []byte, getNodeType func(*tree_sitter.Node) string)

ProcessFunctionCall handles a function call

func (*SideEffectTracker) ProcessRead

func (st *SideEffectTracker) ProcessRead(node *tree_sitter.Node, content []byte, getNodeType func(*tree_sitter.Node) string)

ProcessRead handles a variable/field read

func (*SideEffectTracker) ProcessThrow

func (st *SideEffectTracker) ProcessThrow(node *tree_sitter.Node, throwType string)

ProcessThrow handles a throw/panic/raise statement

func (*SideEffectTracker) ProcessTryFinally

func (st *SideEffectTracker) ProcessTryFinally()

ProcessTryFinally handles a try-finally block

func (*SideEffectTracker) SetReceiver

func (st *SideEffectTracker) SetReceiver(name, receiverType string)

SetReceiver sets the method receiver

type TreeSitterParser

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

func GetParserForLanguage

func GetParserForLanguage(language string, store *core.FileContentStore) *TreeSitterParser

GetParserForLanguage returns a parser instance for the specified language

func GetSharedParser

func GetSharedParser() *TreeSitterParser

GetSharedParser returns a parser instance from the pool This avoids the overhead of creating parsers while maintaining thread safety

func GetSharedParserWithStore

func GetSharedParserWithStore(store *core.FileContentStore) *TreeSitterParser

GetSharedParserWithStore returns a parser from the pool configured with a FileContentStore Call ReleaseParser when done to return it to the pool

func NewProjectSpecificParser

func NewProjectSpecificParser(store *core.FileContentStore, projectRoot string) *TreeSitterParser

NewProjectSpecificParser creates a parser optimized for a specific project It only loads language parsers for extensions actually present in the project

func NewTreeSitterParser

func NewTreeSitterParser() *TreeSitterParser

func (*TreeSitterParser) GetLanguageFromExtension

func (p *TreeSitterParser) GetLanguageFromExtension(ext string) string

Phase 5: GetLanguageFromExtension returns language name for cache optimization

func (*TreeSitterParser) GetSupportedLanguages

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

GetSupportedLanguages returns a list of all supported languages

func (*TreeSitterParser) ParseFile

func (p *TreeSitterParser) ParseFile(path string, content []byte) ([]types.BlockBoundary, []types.Symbol, []types.Import)

func (*TreeSitterParser) ParseFileEnhanced

func (p *TreeSitterParser) ParseFileEnhanced(path string, content []byte) ([]types.BlockBoundary, []types.Symbol, []types.Import, []types.EnhancedSymbol, []types.Reference, []types.ScopeInfo)

ParseFileEnhanced extracts enhanced symbols with relational data (Phase 5: with lazy loading)

func (*TreeSitterParser) ParseFileEnhancedFromStore

func (p *TreeSitterParser) ParseFileEnhancedFromStore(path string, fileID types.FileID) ([]types.BlockBoundary, []types.Symbol, []types.Import, []types.EnhancedSymbol, []types.Reference, []types.ScopeInfo)

ParseFileEnhancedFromStore extracts enhanced symbols using FileID and FileContentStore

func (*TreeSitterParser) ParseFileEnhancedFromStoreWithContext

func (p *TreeSitterParser) ParseFileEnhancedFromStoreWithContext(ctx context.Context, path string, fileID types.FileID) ([]types.BlockBoundary, []types.Symbol, []types.Import, []types.EnhancedSymbol, []types.Reference, []types.ScopeInfo)

ParseFileEnhancedFromStoreWithContext extracts enhanced symbols with context cancellation support using FileContentStore

func (*TreeSitterParser) ParseFileEnhancedWithAST

func (p *TreeSitterParser) ParseFileEnhancedWithAST(path string, content []byte) (*tree_sitter.Tree, []types.BlockBoundary, []types.Symbol, []types.Import, []types.EnhancedSymbol, []types.Reference, []types.ScopeInfo)

ParseFileEnhancedWithAST extracts enhanced symbols and returns the AST for storage

func (*TreeSitterParser) ParseFileEnhancedWithASTAndContext

func (p *TreeSitterParser) ParseFileEnhancedWithASTAndContext(ctx context.Context, path string, content []byte) (*tree_sitter.Tree, []types.BlockBoundary, []types.Symbol, []types.Import, []types.EnhancedSymbol, []types.Reference, []types.ScopeInfo)

ParseFileEnhancedWithASTAndContext extracts enhanced symbols and returns the AST with context cancellation support

func (*TreeSitterParser) ParseFileEnhancedWithASTAndContextStringRef

func (p *TreeSitterParser) ParseFileEnhancedWithASTAndContextStringRef(ctx context.Context, path string, content []byte, fileID types.FileID) (*tree_sitter.Tree, []types.BlockBoundary, []types.Symbol, []types.Import, []types.EnhancedSymbol, []types.Reference, []types.ScopeInfo)

ParseFileEnhancedWithASTAndContextStringRef extracts enhanced symbols using StringRef for zero-copy operations

func (*TreeSitterParser) ParseFileEnhancedWithContext

func (p *TreeSitterParser) ParseFileEnhancedWithContext(ctx context.Context, path string, content []byte) ([]types.BlockBoundary, []types.Symbol, []types.Import, []types.EnhancedSymbol, []types.Reference, []types.ScopeInfo)

ParseFileEnhancedWithContext extracts enhanced symbols with context cancellation support

func (*TreeSitterParser) ParseFileFromStore

func (p *TreeSitterParser) ParseFileFromStore(path string, fileID types.FileID) ([]types.BlockBoundary, []types.Symbol, []types.Import)

ParseFileFromStore parses a file using FileID and FileContentStore

func (*TreeSitterParser) ParseFileWithContext

func (p *TreeSitterParser) ParseFileWithContext(ctx context.Context, path string, content []byte) ([]types.BlockBoundary, []types.Symbol, []types.Import)

ParseFileWithContext parses a file with context cancellation support

func (*TreeSitterParser) ParseFileWithPerfData

ParseFileWithPerfData parses a file and returns performance analysis data alongside standard results. This method extracts loops, awaits, and calls during AST traversal for performance anti-pattern detection.

func (*TreeSitterParser) ParseFileWithSideEffects

func (p *TreeSitterParser) ParseFileWithSideEffects(ctx context.Context, path string, content []byte, fileID types.FileID) (
	tree *tree_sitter.Tree,
	blocks []types.BlockBoundary,
	symbols []types.Symbol,
	imports []types.Import,
	enhancedSymbols []types.EnhancedSymbol,
	references []types.Reference,
	scopeInfo []types.ScopeInfo,
	perfData []types.FunctionPerfData,
	sideEffects map[string]*types.SideEffectInfo,
)

ParseFileWithSideEffects parses a file and extracts all data including side effect analysis. This is the most comprehensive parsing method, enabling function purity detection.

func (*TreeSitterParser) SetFileContentStore

func (p *TreeSitterParser) SetFileContentStore(store *core.FileContentStore)

SetFileContentStore sets the file content store for this parser instance

type UnifiedExtractor

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

UnifiedExtractor performs all AST extraction in a single tree walk. This consolidates what were previously 6+ separate operations: 1. extractNestedScopes - scope hierarchy extraction 2. extractReferences - reference extraction (language-specific) 3. declaration metadata extraction (signatures, doc comments) 4. walkNodeForCyclomatic - complexity calculation per function 5. detectContextAttributes - attribute detection 6. extractBasicSymbols - symbol, block, and import extraction

Performance impact: ~60% CPU reduction by eliminating redundant CGO calls (ts_node_child, ts_node_child_count, ts_node_type were called 6x per node)

func GetPooledExtractor

func GetPooledExtractor(parser *TreeSitterParser, content []byte, fileID types.FileID, ext, path string) *UnifiedExtractor

GetPooledExtractor gets an extractor from the pool and initializes it for use This reduces allocation overhead by reusing pre-allocated slices and maps

func NewUnifiedExtractor

func NewUnifiedExtractor(parser *TreeSitterParser, content []byte, fileID types.FileID, ext, path string) *UnifiedExtractor

NewUnifiedExtractor creates a new unified extractor for single-pass AST processing

func (*UnifiedExtractor) EnableSideEffectTracking

func (ue *UnifiedExtractor) EnableSideEffectTracking()

EnableSideEffectTracking enables side effect analysis for this extractor. This must be called before Extract() to enable tracking. Side effect tracking adds ~10-15% overhead but provides purity analysis.

func (*UnifiedExtractor) Extract

func (ue *UnifiedExtractor) Extract(tree *tree_sitter.Tree)

Extract performs the unified single-pass extraction Returns without processing if tree is nil (which indicates a parsing error). This is an expected condition for unparseable files, not an error.

func (*UnifiedExtractor) GetAllResults

GetAllResults returns all extracted data including symbols, blocks, and imports

func (*UnifiedExtractor) GetPerfAnalysisResults

func (ue *UnifiedExtractor) GetPerfAnalysisResults() []PerfAnalysisResult

GetPerfAnalysisResults returns the collected performance analysis data

func (*UnifiedExtractor) GetResults

GetResults returns all extracted data (legacy signature for backward compatibility)

func (*UnifiedExtractor) GetSideEffectResults

func (ue *UnifiedExtractor) GetSideEffectResults() map[string]*types.SideEffectInfo

GetSideEffectResults returns the side effect analysis results. Returns nil if side effect tracking was not enabled.

func (*UnifiedExtractor) Lookup

func (ue *UnifiedExtractor) Lookup(line, column int) (string, string)

Lookup implements DeclarationLookup interface for use with buildEnhancedSymbols This is an alias for LookupDeclaration to match the interface

func (*UnifiedExtractor) LookupDeclaration

func (ue *UnifiedExtractor) LookupDeclaration(line, column int) (string, string)

LookupDeclaration retrieves signature and doc comment for a symbol at given position

func (*UnifiedExtractor) Reset

func (ue *UnifiedExtractor) Reset()

Reset clears the extractor state while retaining allocated slice/map capacity This enables efficient reuse via sync.Pool

type VisitContext

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

VisitContext maintains context during tree traversal to eliminate parent chain walking

func NewVisitContext

func NewVisitContext() *VisitContext

NewVisitContext creates a new VisitContext for tree traversal

func (*VisitContext) GetImmediateParent

func (ctx *VisitContext) GetImmediateParent() string

GetImmediateParent returns the current parent type (top of stack)

func (*VisitContext) IsFunctionHandled

func (ctx *VisitContext) IsFunctionHandled(nodeID uintptr) bool

IsFunctionHandled checks if a function node was already processed

func (*VisitContext) IsInParentType

func (ctx *VisitContext) IsInParentType(parentType string) bool

IsInParentType checks if we're currently in any parent of the given type

func (*VisitContext) IsPropertyHandled

func (ctx *VisitContext) IsPropertyHandled(nodeID uintptr) bool

IsPropertyHandled checks if a property node was already processed

func (*VisitContext) MarkFunctionHandled

func (ctx *VisitContext) MarkFunctionHandled(nodeID uintptr)

MarkFunctionHandled marks a function node as processed by a call_expression

func (*VisitContext) MarkPropertyHandled

func (ctx *VisitContext) MarkPropertyHandled(nodeID uintptr)

MarkPropertyHandled marks a property node as processed by a member_expression

func (*VisitContext) PopParent

func (ctx *VisitContext) PopParent()

PopParent removes the most recent parent type from the context stack

func (*VisitContext) PushParent

func (ctx *VisitContext) PushParent(parentType string)

PushParent adds a parent type to the context stack

func (*VisitContext) Reset

func (ctx *VisitContext) Reset()

Reset clears the context state for reuse

Jump to

Keyboard shortcuts

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