parser

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyParseTree = errors.New("parser: parse produced an empty tree")

ErrEmptyParseTree is returned when Tree-Sitter returns a nil tree for valid input.

View Source
var ErrLanguageNotRegistered = errors.New("parser: language not registered")

ErrLanguageNotRegistered is returned when the requested language has no registered grammar.

View Source
var ErrParserCreationFailed = errors.New("parser: failed to create parser instance")

ErrParserCreationFailed is returned when a new Tree-Sitter parser cannot be allocated.

View Source
var ErrUnsupportedLanguage = errors.New("parser: unsupported file type")

ErrUnsupportedLanguage is returned when a file's language is not supported.

Functions

This section is empty.

Types

type Cache

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

Cache is an LRU cache with O(1) operations and memory limits

func NewCache

func NewCache(maxEntries int) *Cache

NewCache creates a new cache with entry and memory limits MEMORY FIX: Reduced default memory limit from 256MB to 32MB for multi-threaded usage

func NewCacheWithMemoryLimit

func NewCacheWithMemoryLimit(maxEntries int, maxMemory int64) *Cache

NewCacheWithMemoryLimit creates a cache with custom memory limit MEMORY FIX: Reduced default max entries from 1000 to 100 for multi-threaded usage

func (*Cache) Clear

func (c *Cache) Clear()

Clear clears all entries from the cache - O(n) but infrequent MEMORY FIX: Now properly closes all trees to release AST memory

func (*Cache) Get

func (c *Cache) Get(key string) *CachedParse

Get retrieves a cached parse result - O(1) Uses an optimistic read → upgrade pattern: check existence under RLock, then re-acquire a write lock only when a hit is confirmed (MoveToFront mutates the list).

func (*Cache) MemoryUsage

func (c *Cache) MemoryUsage() int64

MemoryUsage returns current memory usage estimate

func (*Cache) Put

func (c *Cache) Put(key string, data *CachedParse)

Put adds or updates a cached parse result - O(1)

func (*Cache) Remove

func (c *Cache) Remove(key string)

Remove removes an entry from the cache - O(1) MEMORY FIX: Now properly closes the tree to release AST memory

func (*Cache) Size

func (c *Cache) Size() int

Size returns the current number of cached items

func (*Cache) Stats

func (c *Cache) Stats() (hits, misses int64)

Stats returns cache statistics

func (*Cache) StatsWithMemory

func (c *Cache) StatsWithMemory() (hits, misses, memUsage int64)

StatsWithMemory returns cache statistics including memory usage

type CachedParse

type CachedParse struct {
	Root   *sitter.Node
	Tree   *sitter.Tree // Keep tree reference to close on eviction
	Source []byte
}

CachedParse represents a cached parse result MEMORY FIX: Now stores the Tree reference to properly close it on eviction

type ParseResult

type ParseResult struct {
	Root     *sitter.Node
	Source   []byte
	Language string
	FilePath string
}

ParseResult contains the result of parsing a file

type Service

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

Service provides parsing capabilities for multiple languages

func NewService

func NewService(cacheSize ...int) *Service

NewService creates a new parser service

func (*Service) CacheStats

func (s *Service) CacheStats() (hits, misses int64)

CacheStats returns cache statistics

func (*Service) ClearCache

func (s *Service) ClearCache()

ClearCache clears the parser cache

func (*Service) DetectLanguage

func (s *Service) DetectLanguage(filePath string) string

DetectLanguage detects the programming language from file path. Uses the centralized extension mappings from pkg/parser/languages.

func (*Service) GetLanguage

func (s *Service) GetLanguage(name string) *sitter.Language

GetLanguage returns the registered language by name

func (*Service) IsSupported

func (s *Service) IsSupported(filePath string) bool

IsSupported checks if a file type is supported

func (*Service) ParseFile

func (s *Service) ParseFile(filePath string) (*ParseResult, error)

ParseFile parses a file and returns the parse result MEMORY FIX: Now stores tree in cache for proper cleanup on eviction

func (*Service) ParseWithTree

func (s *Service) ParseWithTree(source []byte, language string) (*sitter.Tree, *sitter.Node, error)

ParseWithTree parses source code and returns both tree and root node MEMORY FIX: Now returns the tree so it can be closed later

func (*Service) RegisterLanguage

func (s *Service) RegisterLanguage(name string, lang *sitter.Language)

RegisterLanguage registers a language parser

func (*Service) SupportedLanguages

func (s *Service) SupportedLanguages() []string

SupportedLanguages returns all supported language names

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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