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

engine

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package engine defines the narrow tree-sitter surface pkg/semantics relies on. It is deliberately not a general-purpose tree-sitter binding: it exposes exactly the Node/Tree/Parser/Query operations go_imports.go, ts_imports.go, go_features.go, ts_features.go, and parser.go use today -- no NamedChild, no TreeCursor/Walk, no query predicates, no incremental parsing.

This package lives under pkg/semantics/internal so it is importable only from within pkg/semantics itself; it is not part of any public API.

Adapts github.com/odvcencio/gotreesitter (a from-scratch, CGO-free reimplementation of the Tree-sitter runtime) to the engine interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Language

type Language interface {
	NewParser() (Parser, error)
	NewQuery(source string) (Query, error)
	NewQueryCursor() QueryCursor
}

Language is a backend-bound handle for one of pkg/semantics's supported grammars. It is the sole seam between pkg/semantics's language.go and a concrete backend implementation.

func GoTreeSitterLanguage

func GoTreeSitterLanguage(name string) Language

GoTreeSitterLanguage adapts a gotreesitter grammar, looked up by its registered name (e.g. "go", "typescript", "tsx"), into a Language. name must be registered in github.com/odvcencio/gotreesitter/grammars -- typically via a matching grammar_subset_<name> build tag (see mise.toml's wasm-build task). An unregistered name is a build configuration error, not a runtime condition callers should need to handle, so this panics rather than returning an error: it is only ever called from package-init-time languageRegistry construction with names this package controls.

type Node

type Node interface {
	Kind() string
	HasError() bool
	IsError() bool
	IsMissing() bool
	ChildCount() int
	// Child returns the i'th child, or nil if i is out of range.
	Child(i int) Node
	// ChildByFieldName returns the child bound to name, or nil if absent.
	ChildByFieldName(name string) Node
	// Parent returns the parent node, or nil for the root.
	Parent() Node
	StartByte() uint
	EndByte() uint
	StartPoint() (row, col uint)
	EndPoint() (row, col uint)
	Utf8Text(source []byte) string
}

Node is one node in a parsed syntax tree.

type Parser

type Parser interface {
	Parse(content []byte) (Tree, error)
}

Parser parses source bytes into a Tree for the Language it was created for.

type Query

type Query interface {
	Close()
}

Query is a compiled tree-sitter query. A Query is valid only against trees parsed with the exact Language it was compiled against; this invariant is preserved by construction, since every Query is created via that Language's own NewQuery method.

type QueryCapture

type QueryCapture struct {
	Node  Node
	Index uint32
}

QueryCapture is one capture within a QueryMatch.

type QueryCursor

type QueryCursor interface {
	Matches(query Query, root Node, source []byte) QueryMatches
	Close()
}

QueryCursor runs a Query against one Node/source pair. The caller owns the returned QueryCursor and must call Close when done with it.

type QueryMatch

type QueryMatch struct {
	Captures []QueryCapture
}

QueryMatch is one match yielded during query iteration.

type QueryMatches

type QueryMatches interface {
	Next() *QueryMatch
}

QueryMatches iterates a Query's matches against one Node/source pair. Next returns nil once iteration is exhausted.

type Tree

type Tree interface {
	RootNode() Node
	Close()
}

Tree is a parsed syntax tree. The caller owns the returned Tree and must call Close when done with it.

Jump to

Keyboard shortcuts

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