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

treesitter

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package treesitter implements parser.ParserPort with the official CGO go-tree-sitter bindings (docs/adr/0002). It parses source into Båge's engine-agnostic CST DTOs, retaining the native tree on parser.Tree.Native so incremental reparsing and changed-range queries can reuse it.

Lifecycle: every returned *parser.Tree owns a native tree; the caller MUST call Tree.Close to free the underlying C memory. Parsers are created and closed per call.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedLang = errors.New("treesitter: unsupported language")

ErrUnsupportedLang is returned when no grammar is registered for a language.

Functions

This section is empty.

Types

type Adapter

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

Adapter is a parser.ParserPort backed by go-tree-sitter. It caches one *ts.Language per supported language for the process lifetime. The zero value is not usable; construct it with New.

func New

func New() *Adapter

New constructs an Adapter with every resolved grammar registered, making the adapter polyglot. TypeScript and TSX both come from the tree-sitter-typescript binding via its two distinct exported language functions.

func (*Adapter) ChangedRanges

func (a *Adapter) ChangedRanges(old, new *parser.Tree) []parser.ByteRange

ChangedRanges reports the byte ranges that differ between old and new. Both must carry native trees from this adapter; otherwise it returns nil.

func (*Adapter) Parse

func (a *Adapter) Parse(ctx context.Context, lang parser.Lang, src []byte) (*parser.Tree, error)

Parse parses src under lang into a fresh Tree whose Native holds the engine tree (close it via Tree.Close).

func (*Adapter) ParseIncremental

func (a *Adapter) ParseIncremental(ctx context.Context, lang parser.Lang, src []byte, old *parser.Tree, edit parser.InputEdit) (*parser.Tree, error)

ParseIncremental applies edit to old's native tree and reparses src, reusing unchanged subtrees. old must carry a native tree from this adapter.

Jump to

Keyboard shortcuts

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