Documentation
¶
Overview ¶
Package treesitter runs tree-sitter language modules in WebAssembly with wazero. A module is the tree-sitter runtime, one grammar and the shim, built by github.com/tyler-builds/jamb-grammars (see its shim/shim.c and its internal/grammarbuild); highlight.ABI is the version of the shim's interface that this package calls. The package compiles each module once per process, keeps the compiled code in a per-user cache directory, and creates an Instance for each document. An Instance holds one document: its text, parser, tree and highlight query. Instances are not safe for concurrent use, so each one has a single owner that calls it from one goroutine.
Index ¶
- type Instance
- func (in *Instance) CaptureNames() ([]string, error)
- func (in *Instance) Close() error
- func (in *Instance) Edit(start, oldEnd int, text []byte) error
- func (in *Instance) Init(text []byte) error
- func (in *Instance) MemorySize() uint32
- func (in *Instance) Parse(full bool) error
- func (in *Instance) SetQuery(q []byte) error
- func (in *Instance) Spans(lo, hi int, dst []uint32) ([]uint32, error)
- func (in *Instance) TreeHasError() (bool, error)
- func (in *Instance) TreeHash(fresh bool) (uint64, error)
- type Module
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance is one instance of a module, holding one document. It is not safe for concurrent use. After a call returns an error from the module, the instance may be left in an unknown state and should be closed.
func (*Instance) CaptureNames ¶
CaptureNames returns the names of the query's captures, indexed by the capture numbers that Spans returns.
func (*Instance) Edit ¶
Edit replaces the bytes from start to oldEnd with text, and edits the tree to match. The edit is not reparsed until Parse. It returns an error if the range is not inside the document.
func (*Instance) Init ¶
Init sets the document's text and selects the module's grammar. Any earlier tree is discarded, so the next Parse must be a full parse.
func (*Instance) MemorySize ¶
MemorySize returns the size of the instance's linear memory in bytes.
func (*Instance) Parse ¶
Parse parses the document. With full set it parses from scratch, otherwise it reuses the tree that the edits have been applied to.
func (*Instance) SetQuery ¶
SetQuery compiles the highlight query against the grammar. When the query does not match the grammar, the error gives the byte offset of the problem in the query text.
func (*Instance) Spans ¶
Spans appends to dst the highlight captures that intersect bytes lo to hi, as (start, end, capture index) triples in the order the query yields them, and returns the extended slice.
func (*Instance) TreeHasError ¶
TreeHasError reports whether the current tree contains an error node.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is a compiled language module. Its instances share the compiled code.
func Compile ¶
Compile returns the compiled form of wasm, compiling it on first use. wasm must be a module built as described in the package comment, and must not be changed afterwards. The result is cached per process, keyed by the address of wasm's bytes.
func (*Module) Instantiate ¶
Instantiate creates a new instance of the module. The instance starts with no document; call Init first.