Help us shape the future of Go! Take the 2026 Go Developer Survey

tsutil

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tsutil holds tree-sitter helpers shared across the per-language extractors: a per-language parser pool and a tiny query-compile-once wrapper. Internal — not part of the public API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureIndex

func CaptureIndex(q *ts.Query, name string) int

CaptureIndex returns the index of a named capture in q, or -1 if the name is not present. Used at init time to pre-resolve capture names so the hot match-iteration loop can index by uint instead of string.

func MustCompileQuery

func MustCompileQuery(lang *ts.Language, source, name string) *ts.Query

MustCompileQuery compiles a tree-sitter query at package init time and panics on failure. The query string is embedded at build time, so a compile error is a developer bug, not a runtime condition — panic is the right escalation.

Types

type CursorPool

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

CursorPool hands out *ts.QueryCursor instances. Cursors are also not goroutine-safe individually but are cheap to allocate; pooling avoids the allocation in tight loops.

func NewCursorPool

func NewCursorPool() *CursorPool

NewCursorPool returns an empty pool. Cursors are created lazily.

func (*CursorPool) Get

func (cp *CursorPool) Get() *ts.QueryCursor

Get returns a fresh-or-recycled cursor.

func (*CursorPool) Put

func (cp *CursorPool) Put(c *ts.QueryCursor)

Put returns a cursor to the pool.

type ParserPool

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

ParserPool hands out *ts.Parser instances pre-bound to a single language. Parsers are not goroutine-safe individually; the pool lets concurrent callers pick one, parse, return.

func NewParserPool

func NewParserPool(lang *ts.Language) *ParserPool

NewParserPool returns a pool that produces parsers bound to lang.

func (*ParserPool) Get

func (pp *ParserPool) Get() *ts.Parser

Get returns a parser ready to Parse. Callers must Put the parser back when done.

func (*ParserPool) Put

func (pp *ParserPool) Put(p *ts.Parser)

Put returns a parser to the pool. The parser is not Closed — pool users own its lifetime.

Jump to

Keyboard shortcuts

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