tsparse

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package tsparse wraps the gotreesitter pure-Go tree-sitter runtime, exposing a thin Parser type and a Node type that the rest of the codebase can walk without importing gotreesitter directly.

See docs/adr/001-parser-wazero.md (STATUS section) for the rationale for using gotreesitter instead of raw wazero + WASM grammars.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(n *Node, fn func(*Node))

Walk calls fn on every node in the tree in pre-order depth-first order.

Types

type Language

type Language int

Language identifies which grammar to use.

const (
	LangGo Language = iota
	LangTypeScript
	// LangTSX selects the tree-sitter `tsx` grammar, a superset of the
	// typescript grammar that also parses JSX. Used for .tsx/.jsx files.
	LangTSX
	// LangPython selects the tree-sitter `python` grammar (Python 3).
	LangPython
	// LangCSharp selects the tree-sitter `c-sharp` grammar.
	LangCSharp
	// LangJava selects the tree-sitter `java` grammar.
	LangJava
	// LangKotlin selects the tree-sitter `kotlin` grammar.
	LangKotlin
	// LangRuby selects the tree-sitter `ruby` grammar.
	LangRuby
	// LangRust selects the tree-sitter `rust` grammar.
	LangRust
	// LangPHP selects the tree-sitter `php` grammar.
	LangPHP
	// LangC selects the tree-sitter `c` grammar.
	LangC
	// LangScala selects the tree-sitter `scala` grammar.
	LangScala
	// LangSwift selects the tree-sitter `swift` grammar.
	LangSwift
	// LangCPP selects the tree-sitter `cpp` grammar (a superset of `c`).
	LangCPP
	// LangDart selects the tree-sitter `dart` grammar.
	LangDart
	// LangLua selects the tree-sitter `lua` grammar.
	LangLua
	// LangElixir selects the tree-sitter `elixir` grammar.
	LangElixir
	// LangHaskell selects the tree-sitter `haskell` grammar.
	LangHaskell
	// LangObjC selects the tree-sitter `objc` grammar (a superset of `c`).
	LangObjC
	// LangPerl selects the tree-sitter `perl` grammar.
	LangPerl
	// LangErlang selects the tree-sitter `erlang` grammar.
	LangErlang
	// LangJulia selects the tree-sitter `julia` grammar.
	LangJulia
	// LangFSharp selects the tree-sitter `fsharp` grammar.
	LangFSharp
	// LangR selects the tree-sitter `r` grammar.
	LangR
	// LangBash selects the tree-sitter `bash` grammar.
	LangBash
	// LangPowerShell selects the tree-sitter `powershell` grammar.
	LangPowerShell
	// LangSql selects the tree-sitter `sql` grammar.
	LangSql
)

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is a syntax-tree node. The zero value is not valid.

func (*Node) Child

func (n *Node) Child(i int) *Node

Child returns the i-th child (0-indexed).

func (*Node) ChildByFieldName

func (n *Node) ChildByFieldName(name string) *Node

ChildByFieldName returns the child with the given field name, or nil.

func (*Node) ChildCount

func (n *Node) ChildCount() int

ChildCount returns the total number of children (named + anonymous).

func (*Node) EndPoint

func (n *Node) EndPoint() Point

EndPoint returns the 0-based (row, column) one past the last byte.

func (*Node) FieldNameForChild

func (n *Node) FieldNameForChild(i int) string

FieldNameForChild returns the field name (if any) for the i-th child.

func (*Node) HasError

func (n *Node) HasError() bool

HasError reports whether this node or any descendant is an ERROR node.

func (*Node) IsNamed

func (n *Node) IsNamed() bool

IsNamed reports whether this node is named (not an anonymous token).

func (*Node) Kind

func (n *Node) Kind() string

Kind returns the grammar node type (e.g. "function_declaration").

func (*Node) NamedChild

func (n *Node) NamedChild(i int) *Node

NamedChild returns the i-th named child (0-indexed).

func (*Node) NamedChildCount

func (n *Node) NamedChildCount() int

NamedChildCount returns the number of named (non-anonymous) children.

func (*Node) StartPoint

func (n *Node) StartPoint() Point

StartPoint returns the 0-based (row, column) of the first byte.

func (*Node) Text

func (n *Node) Text() string

Text returns the source bytes this node spans.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses source files for a fixed language.

func NewParser

func NewParser(lang Language) (*Parser, error)

NewParser returns a Parser for the given Language.

func (*Parser) Parse

func (p *Parser) Parse(src []byte) (*Tree, error)

Parse parses src and returns the syntax tree.

type Point

type Point struct {
	Row    uint32
	Column uint32
}

Point is a (row, column) position in source text (0-indexed).

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree is a parsed syntax tree.

func (*Tree) RootNode

func (t *Tree) RootNode() *Node

RootNode returns the root of the syntax tree.

Jump to

Keyboard shortcuts

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