walk

package
v0.48.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package walk is the grammar-free core of taproot: load a tree-sitter Language from a pre-generated blob and navigate the CST with a Walker. It depends only on the gotreesitter runtime — NOT on grammargen or the grammars registry — so a DSL that embeds a generated grammar blob can parse and highlight without linking the ~200-grammar registry (~22MB). The grammargen-backed fallback helpers (build-from-DSL) stay in the parent taproot package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LanguageFromBlob

func LanguageFromBlob(name string, blob []byte) (*gts.Language, error)

LanguageFromBlob loads and caches (once per name) the tree-sitter Language from a pre-generated grammar blob. Grammar-free: there is no grammargen DSL fallback (use taproot.LanguageFromBlob for that).

Types

type Walker

type Walker struct {
	Lang *gts.Language
	Src  []byte
}

Walker bundles a parse's language and source bytes with CST cursor helpers.

func NewWalker

func NewWalker(lang *gts.Language, src []byte) *Walker

NewWalker constructs a Walker for the given language and source.

func ParseFromBlob

func ParseFromBlob(name string, blob []byte, src []byte) (*gts.Node, *Walker, error)

ParseFromBlob loads the language from a blob (grammar-free) then parses src.

func ParseWithLanguage

func ParseWithLanguage(lang *gts.Language, src []byte) (*gts.Node, *Walker, error)

ParseWithLanguage parses src with lang, returning the root node, a Walker, and a syntax error if the tree has error/missing nodes.

func (*Walker) ChildByType

func (w *Walker) ChildByType(n *gts.Node, typ string) *gts.Node

ChildByType returns the first direct child of n with grammar type typ, or nil.

func (*Walker) Field

func (w *Walker) Field(n *gts.Node, field string) *gts.Node

Field returns the child of n that is bound to the named field, or nil.

func (*Walker) Pos

func (w *Walker) Pos(n *gts.Node) (line, col int)

Pos returns the 1-based line and column where n begins.

func (*Walker) SyntaxError

func (w *Walker) SyntaxError(root *gts.Node) error

SyntaxError walks the subtree rooted at root to find the best error or missing leaf and returns a formatted error.

func (*Walker) Text

func (w *Walker) Text(n *gts.Node) string

Text returns the source text spanned by n.

func (*Walker) Type

func (w *Walker) Type(n *gts.Node) string

Type returns the grammar type name of n.

Jump to

Keyboard shortcuts

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