tspool

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tspool provides pooled tree-sitter parsers for concurrent parsing.

This package centralizes parser pooling logic to:

  • Enable reuse across different parser components
  • Reduce parser allocation overhead via sync.Pool
  • Ensure thread-safe parser sharing

Separate pools are maintained per language (Go, JavaScript, TypeScript) to avoid language switching overhead.

Thread-safety: Parsers returned by Get are NOT safe for concurrent use. Each goroutine must Get its own parser or use the Parse helper.

Index

Constants

View Source
const MaxTreeDepth = 1000

MaxTreeDepth is the maximum recursion depth when walking AST trees.

Variables

This section is empty.

Functions

func Get

func Get(lang domain.Language) *sitter.Parser

Get returns a pooled parser for the given language. The returned parser is NOT safe for concurrent use. Use Put to return the parser after use.

func GetLanguage

func GetLanguage(lang domain.Language) *sitter.Language

GetLanguage returns the tree-sitter language for the given domain language.

func Parse

func Parse(ctx context.Context, lang domain.Language, source []byte) (*sitter.Tree, error)

Parse parses source using a pooled parser. Caller MUST call tree.Close() to free resources. The parser is automatically returned to the pool after parsing.

func Put

func Put(lang domain.Language, parser *sitter.Parser)

Put returns a parser to the pool.

Types

This section is empty.

Jump to

Keyboard shortcuts

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