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 ¶
- Variables
- type Adapter
- func (a *Adapter) ChangedRanges(old, new *parser.Tree) []parser.ByteRange
- func (a *Adapter) Parse(ctx context.Context, lang parser.Lang, src []byte) (*parser.Tree, error)
- func (a *Adapter) ParseIncremental(ctx context.Context, lang parser.Lang, src []byte, old *parser.Tree, ...) (*parser.Tree, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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.