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 ¶
- func Walk(n *Node, fn func(*Node))
- type Language
- type Node
- func (n *Node) Child(i int) *Node
- func (n *Node) ChildByFieldName(name string) *Node
- func (n *Node) ChildCount() int
- func (n *Node) EndPoint() Point
- func (n *Node) FieldNameForChild(i int) string
- func (n *Node) HasError() bool
- func (n *Node) IsNamed() bool
- func (n *Node) Kind() string
- func (n *Node) NamedChild(i int) *Node
- func (n *Node) NamedChildCount() int
- func (n *Node) StartPoint() Point
- func (n *Node) Text() string
- type Parser
- type Point
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) ChildByFieldName ¶
ChildByFieldName returns the child with the given field name, or nil.
func (*Node) ChildCount ¶
ChildCount returns the total number of children (named + anonymous).
func (*Node) FieldNameForChild ¶
FieldNameForChild returns the field name (if any) for the i-th child.
func (*Node) NamedChild ¶
NamedChild returns the i-th named child (0-indexed).
func (*Node) NamedChildCount ¶
NamedChildCount returns the number of named (non-anonymous) children.
func (*Node) StartPoint ¶
StartPoint returns the 0-based (row, column) of the first byte.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses source files for a fixed language.