Documentation
¶
Overview ¶
Package taproot is the common front-end harness shared by M31 DSLs that use the gotreesitter runtime. It provides:
- Language: grammar generation + per-name caching (sync.Mutex + map).
- Walker: a bundle of *Language + source bytes with CST cursor helpers.
- Parse: the one-stop flow (Language → parse → error check).
- LanguageFromBlob/ParseFromBlob: the same cache/parse flow, but preferring an embedded pre-generated grammar blob when one is available.
The error-leaf finder in Walker.SyntaxError is lifted from ~/work/elio/parse/tree.go (treeWalker.syntaxError): it collects every ERROR/MISSING leaf, picks the latest-positioned one — preferring MISSING nodes because they pinpoint expected-but-absent tokens — and formats either "expected <type>" (MISSING) or "near <text>" (ERROR).
Index ¶
- func Language(name string, build func() *grammargen.Grammar) (*gts.Language, error)
- func LanguageFromBlob(name string, blob []byte, build func() *grammargen.Grammar) (*gts.Language, error)
- type Walker
- func (w *Walker) ChildByType(n *gts.Node, typ string) *gts.Node
- func (w *Walker) Field(n *gts.Node, field string) *gts.Node
- func (w *Walker) Pos(n *gts.Node) (line, col int)
- func (w *Walker) SyntaxError(root *gts.Node) error
- func (w *Walker) Text(n *gts.Node) string
- func (w *Walker) Type(n *gts.Node) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Language ¶
Language generates and caches (once per name) the tree-sitter Language for a grammar. build is called only on a cache miss; subsequent calls for the same name return the cached result without calling build again.
func LanguageFromBlob ¶
func LanguageFromBlob(name string, blob []byte, build func() *grammargen.Grammar) (*gts.Language, error)
LanguageFromBlob loads and caches (once per name) the tree-sitter Language from blob when possible, falling back to build when blob is empty or corrupt. This is the fast path for DSLs that embed a generated grammar blob but still want a source grammar fallback during development.
Types ¶
type Walker ¶
Walker bundles a parse's language and source bytes with CST cursor helpers. Lifted from elio/parse/tree.go (treeWalker) and confirmed against selena/parse/parse.go (walker) and eos/syntax/cst.go (cstLowerer).
func Parse ¶
Parse runs the full common DSL parse flow:
- Obtain (or generate+cache) the Language for name.
- Parse src with a new Parser.
- If the root HasError, return (root, walker, walker.SyntaxError(root)).
- Otherwise return (root, walker, nil).
root and walker are always non-nil when the language step and parse step succeed (even when a syntax error is present), so callers can inspect the partial tree.
func ParseFromBlob ¶
func ParseFromBlob(name string, blob []byte, build func() *grammargen.Grammar, src []byte) (*gts.Node, *Walker, error)
ParseFromBlob is the blob-aware variant of Parse. It obtains the language via LanguageFromBlob, then follows the same parse/error flow as Parse.
func (*Walker) ChildByType ¶
ChildByType returns the first direct child of n with grammar type typ, or nil.
func (*Walker) SyntaxError ¶
SyntaxError walks the subtree rooted at root to find the best error or missing leaf and returns a formatted error.
Strategy (lifted from elio/parse/tree.go treeWalker.syntaxError):
- Collect every leaf that is an ERROR node or a MISSING node.
- Among those, prefer MISSING (which pinpoints an expected-but-absent token). Among peers of the same kind, pick the latest start byte (where the LR parser got stuck).
- Format as "line:col: syntax error: expected <type>" for MISSING, or "line:col: syntax error near <text>" for ERROR.