Documentation
¶
Overview ¶
Package gotreesitter implements a pure Go tree-sitter runtime.
This file defines the core data structures that mirror tree-sitter's TSLanguage C struct and related types. They form the foundation on which the lexer, parser, query engine, and syntax tree are built.
Index ¶
- Constants
- Variables
- func RunExternalScanner(lang *Language, payload any, lexer *ExternalLexer, validSymbols []bool) bool
- func Walk(node *Node, fn func(node *Node, depth int) WalkAction)
- type BoundTree
- func (bt *BoundTree) ChildByField(n *Node, fieldName string) *Node
- func (bt *BoundTree) Language() *Language
- func (bt *BoundTree) NodeText(n *Node) string
- func (bt *BoundTree) NodeType(n *Node) string
- func (bt *BoundTree) Release()
- func (bt *BoundTree) RootNode() *Node
- func (bt *BoundTree) Source() []byte
- type ByteSkippableTokenSource
- type ExternalLexer
- type ExternalScanner
- type ExternalScannerState
- type ExternalVMInstr
- func VMAdvance(skip bool) ExternalVMInstr
- func VMEmit(sym Symbol) ExternalVMInstr
- func VMFail() ExternalVMInstr
- func VMIfRuneClass(class ExternalVMRuneClass, alt int) ExternalVMInstr
- func VMIfRuneEq(r rune, alt int) ExternalVMInstr
- func VMIfRuneInRange(start, end rune, alt int) ExternalVMInstr
- func VMJump(target int) ExternalVMInstr
- func VMMarkEnd() ExternalVMInstr
- func VMRequireStateEq(state uint32, alt int) ExternalVMInstr
- func VMRequireValid(validSymbolIndex, alt int) ExternalVMInstr
- func VMSetState(state uint32) ExternalVMInstr
- type ExternalVMOp
- type ExternalVMProgram
- type ExternalVMRuneClass
- type ExternalVMScanner
- func (s *ExternalVMScanner) Create() any
- func (s *ExternalVMScanner) Deserialize(payload any, buf []byte)
- func (s *ExternalVMScanner) Destroy(payload any)
- func (s *ExternalVMScanner) Scan(payload any, lexer *ExternalLexer, validSymbols []bool) bool
- func (s *ExternalVMScanner) Serialize(payload any, buf []byte) int
- type FieldID
- type FieldMapEntry
- type HighlightRange
- type Highlighter
- type HighlighterOption
- type InputEdit
- type Language
- type LexMode
- type LexState
- type LexTransition
- type Lexer
- type Node
- func (n *Node) Child(i int) *Node
- func (n *Node) ChildByFieldName(name string, lang *Language) *Node
- func (n *Node) ChildCount() int
- func (n *Node) Children() []*Node
- func (n *Node) EndByte() uint32
- func (n *Node) EndPoint() Point
- func (n *Node) HasError() bool
- func (n *Node) IsMissing() bool
- func (n *Node) IsNamed() bool
- func (n *Node) NamedChild(i int) *Node
- func (n *Node) NamedChildCount() int
- func (n *Node) NextSibling() *Node
- func (n *Node) Parent() *Node
- func (n *Node) ParseState() StateID
- func (n *Node) PrevSibling() *Node
- func (n *Node) Range() Range
- func (n *Node) StartByte() uint32
- func (n *Node) StartPoint() Point
- func (n *Node) Symbol() Symbol
- func (n *Node) Text(source []byte) string
- func (n *Node) Type(lang *Language) string
- type ParseAction
- type ParseActionEntry
- type ParseActionType
- type Parser
- type Pattern
- type Point
- type PointSkippableTokenSource
- type Query
- type QueryCapture
- type QueryCursor
- type QueryMatch
- type QueryPredicate
- type QueryStep
- type Range
- type StateID
- type Symbol
- type SymbolMetadata
- type Tag
- type Tagger
- type TaggerOption
- type Token
- type TokenSource
- type Tree
- type WalkAction
Constants ¶
const ( // RuntimeLanguageVersion is the maximum tree-sitter language version this // runtime is known to support. RuntimeLanguageVersion uint32 = 14 // MinCompatibleLanguageVersion is the minimum accepted language version. MinCompatibleLanguageVersion uint32 = 13 )
Variables ¶
var DebugDFA bool
DebugDFA enables trace logging for DFA token production.
Functions ¶
func RunExternalScanner ¶
func RunExternalScanner(lang *Language, payload any, lexer *ExternalLexer, validSymbols []bool) bool
RunExternalScanner invokes the language's external scanner if present. Returns true if the scanner produced a token, false otherwise.
Types ¶
type BoundTree ¶
type BoundTree struct {
// contains filtered or unexported fields
}
BoundTree pairs a Tree with its Language and source, eliminating the need to pass *Language and []byte to every node method call.
func Bind ¶
Bind creates a BoundTree from a Tree. The Tree must have been created with a Language (via NewTree or a Parser). Returns a BoundTree that delegates to the underlying Tree's Language and Source.
func (*BoundTree) ChildByField ¶
ChildByField returns the first child assigned to the given field name.
func (*BoundTree) NodeType ¶
NodeType returns the node's type name, resolved via the bound language.
func (*BoundTree) Release ¶
func (bt *BoundTree) Release()
Release releases the underlying tree's arena memory.
type ByteSkippableTokenSource ¶
type ByteSkippableTokenSource interface {
TokenSource
SkipToByte(offset uint32) Token
}
ByteSkippableTokenSource can jump to a byte offset and return the first token at or after that position.
type ExternalLexer ¶
type ExternalLexer struct {
// contains filtered or unexported fields
}
ExternalLexer is the scanner-facing lexer API used by external scanners. It mirrors the essential tree-sitter scanner API: lookahead, advance, mark_end, and result_symbol.
func (*ExternalLexer) Advance ¶
func (l *ExternalLexer) Advance(skip bool)
Advance consumes one rune. When skip is true, consumed bytes are excluded from the token span (scanner whitespace skipping behavior).
func (*ExternalLexer) GetColumn ¶
func (l *ExternalLexer) GetColumn() uint32
GetColumn returns the current column (0-based) at the scanner cursor.
func (*ExternalLexer) Lookahead ¶
func (l *ExternalLexer) Lookahead() rune
Lookahead returns the current rune or 0 at EOF.
func (*ExternalLexer) MarkEnd ¶
func (l *ExternalLexer) MarkEnd()
MarkEnd marks the current scanner position as the token end.
func (*ExternalLexer) SetResultSymbol ¶
func (l *ExternalLexer) SetResultSymbol(sym Symbol)
SetResultSymbol sets the token symbol to emit when Scan returns true.
type ExternalScanner ¶
type ExternalScanner interface {
Create() any
Destroy(payload any)
Serialize(payload any, buf []byte) int
Deserialize(payload any, buf []byte)
Scan(payload any, lexer *ExternalLexer, validSymbols []bool) bool
}
ExternalScanner is the interface for language-specific external scanners. Languages like Python and JavaScript need these for indent tracking, template literals, regex vs division, etc.
type ExternalScannerState ¶
type ExternalScannerState struct {
Data []byte
}
ExternalScannerState holds serialized state for an external scanner between incremental parse runs.
type ExternalVMInstr ¶
type ExternalVMInstr struct {
Op ExternalVMOp
A int32
B int32
Alt int32
}
ExternalVMInstr is one instruction in an external scanner VM program.
Operands:
- A: primary operand (opcode-specific)
- B: secondary operand (used by range checks)
- Alt: alternate program counter when a condition fails
func VMAdvance ¶
func VMAdvance(skip bool) ExternalVMInstr
func VMEmit ¶
func VMEmit(sym Symbol) ExternalVMInstr
func VMFail ¶
func VMFail() ExternalVMInstr
func VMIfRuneClass ¶
func VMIfRuneClass(class ExternalVMRuneClass, alt int) ExternalVMInstr
func VMIfRuneEq ¶
func VMIfRuneEq(r rune, alt int) ExternalVMInstr
func VMIfRuneInRange ¶
func VMIfRuneInRange(start, end rune, alt int) ExternalVMInstr
func VMJump ¶
func VMJump(target int) ExternalVMInstr
func VMMarkEnd ¶
func VMMarkEnd() ExternalVMInstr
func VMRequireStateEq ¶
func VMRequireStateEq(state uint32, alt int) ExternalVMInstr
func VMRequireValid ¶
func VMRequireValid(validSymbolIndex, alt int) ExternalVMInstr
func VMSetState ¶
func VMSetState(state uint32) ExternalVMInstr
type ExternalVMOp ¶
type ExternalVMOp uint8
ExternalVMOp is an opcode for the native-Go external scanner VM.
const ( ExternalVMOpFail ExternalVMOp = iota ExternalVMOpJump ExternalVMOpRequireValid ExternalVMOpRequireStateEq ExternalVMOpSetState ExternalVMOpIfRuneEq ExternalVMOpIfRuneInRange ExternalVMOpIfRuneClass ExternalVMOpAdvance ExternalVMOpMarkEnd ExternalVMOpEmit )
type ExternalVMProgram ¶
type ExternalVMProgram struct {
Code []ExternalVMInstr
MaxSteps int // <=0 uses a safe default based on program size
}
ExternalVMProgram is a small bytecode program interpreted by ExternalVMScanner.
type ExternalVMRuneClass ¶
type ExternalVMRuneClass uint8
ExternalVMRuneClass is a character class used by ExternalVMOpIfRuneClass.
const ( ExternalVMRuneClassWhitespace ExternalVMRuneClass = iota ExternalVMRuneClassDigit ExternalVMRuneClassLetter ExternalVMRuneClassWord ExternalVMRuneClassNewline )
type ExternalVMScanner ¶
type ExternalVMScanner struct {
// contains filtered or unexported fields
}
ExternalVMScanner executes an ExternalVMProgram and implements ExternalScanner.
func MustNewExternalVMScanner ¶
func MustNewExternalVMScanner(program ExternalVMProgram) *ExternalVMScanner
MustNewExternalVMScanner is like NewExternalVMScanner but panics on error.
func NewExternalVMScanner ¶
func NewExternalVMScanner(program ExternalVMProgram) (*ExternalVMScanner, error)
NewExternalVMScanner validates and constructs an ExternalVMScanner.
func (*ExternalVMScanner) Create ¶
func (s *ExternalVMScanner) Create() any
Create allocates scanner payload (currently a single uint32 state slot).
func (*ExternalVMScanner) Deserialize ¶
func (s *ExternalVMScanner) Deserialize(payload any, buf []byte)
Deserialize restores payload state from buf.
func (*ExternalVMScanner) Destroy ¶
func (s *ExternalVMScanner) Destroy(payload any)
Destroy releases scanner payload resources.
func (*ExternalVMScanner) Scan ¶
func (s *ExternalVMScanner) Scan(payload any, lexer *ExternalLexer, validSymbols []bool) bool
Scan executes the scanner program against the current lexer position.
type FieldMapEntry ¶
FieldMapEntry maps a child index to a field name.
type HighlightRange ¶
type HighlightRange struct {
StartByte uint32
EndByte uint32
Capture string // "keyword", "string", "function", etc.
}
HighlightRange represents a styled range of source code, mapping a byte span to a capture name from a highlight query. The editor maps capture names (e.g., "keyword", "string", "function") to FSS style classes.
type Highlighter ¶
type Highlighter struct {
// contains filtered or unexported fields
}
Highlighter is a high-level API that takes source code and returns styled ranges. It combines a Parser, a compiled Query, and a Language to provide a single Highlight() call for the editor.
func NewHighlighter ¶
func NewHighlighter(lang *Language, highlightQuery string, opts ...HighlighterOption) (*Highlighter, error)
NewHighlighter creates a Highlighter for the given language and highlight query (in tree-sitter .scm format). Returns an error if the query fails to compile.
func (*Highlighter) Highlight ¶
func (h *Highlighter) Highlight(source []byte) []HighlightRange
Highlight parses the source code and executes the highlight query, returning a slice of HighlightRange sorted by StartByte. When ranges overlap, inner (more specific) captures take priority over outer ones.
func (*Highlighter) HighlightIncremental ¶
func (h *Highlighter) HighlightIncremental(source []byte, oldTree *Tree) ([]HighlightRange, *Tree)
HighlightIncremental re-highlights source after edits were applied to oldTree. Returns the new highlight ranges and the new parse tree (for use in subsequent incremental calls). Call oldTree.Edit() before calling this.
type HighlighterOption ¶
type HighlighterOption func(*Highlighter)
HighlighterOption configures a Highlighter.
func WithTokenSourceFactory ¶
func WithTokenSourceFactory(factory func(source []byte) TokenSource) HighlighterOption
WithTokenSourceFactory sets a factory function that creates a TokenSource for each Highlight call. This is needed for languages that use a custom lexer bridge (like Go, which uses go/scanner instead of a DFA lexer).
When set, Highlight() calls ParseWithTokenSource instead of Parse.
type InputEdit ¶
type InputEdit struct {
StartByte uint32
OldEndByte uint32
NewEndByte uint32
StartPoint Point
OldEndPoint Point
NewEndPoint Point
}
InputEdit describes a single edit to the source text. It tells the parser what byte range was replaced and what the new range looks like, so the incremental parser can skip unchanged subtrees.
type Language ¶
type Language struct {
Name string
// LanguageVersion is the tree-sitter language ABI version.
// A value of 0 means "unknown/unspecified" and is treated as compatible.
LanguageVersion uint32
// Counts
SymbolCount uint32
TokenCount uint32
ExternalTokenCount uint32
StateCount uint32
LargeStateCount uint32
FieldCount uint32
ProductionIDCount uint32
// Symbol metadata
SymbolNames []string
SymbolMetadata []SymbolMetadata
FieldNames []string // index 0 is ""
// Parse tables
ParseTable [][]uint16 // dense: [state][symbol] -> action index
SmallParseTable []uint16 // compressed sparse table
SmallParseTableMap []uint32 // state -> offset into SmallParseTable
ParseActions []ParseActionEntry
// Lex tables
LexModes []LexMode
LexStates []LexState // main lexer DFA
KeywordLexStates []LexState // keyword lexer DFA (optional)
KeywordCaptureToken Symbol
// Field mapping
FieldMapSlices [][2]uint16 // [production_id] -> (index, length)
FieldMapEntries []FieldMapEntry
// Alias sequences
AliasSequences [][]Symbol // [production_id][child_index] -> alias symbol
// Primary state IDs (for table dedup)
PrimaryStateIDs []StateID
// External scanner (nil if not needed)
ExternalScanner ExternalScanner
ExternalSymbols []Symbol // external token index -> symbol
// InitialState is the parser's start state. In tree-sitter grammars
// this is always 1 (state 0 is reserved for error recovery). For
// hand-built grammars it defaults to 0.
InitialState StateID
// contains filtered or unexported fields
}
Language holds all data needed to parse a specific language. It mirrors tree-sitter's TSLanguage C struct, translated into idiomatic Go types with slice-based tables instead of raw pointers.
func (*Language) CompatibleWithRuntime ¶
CompatibleWithRuntime reports whether this language can be parsed by the current runtime version. Unspecified versions (0) are treated as compatible.
func (*Language) FieldByName ¶
FieldByName returns the field ID for a given name, or (0, false) if not found. Builds an internal map on first call for O(1) subsequent lookups.
func (*Language) SymbolByName ¶
SymbolByName returns the symbol ID for a given name, or (0, false) if not found. The "_" wildcard returns (0, true) as a special case. Builds an internal map on first call for O(1) subsequent lookups.
func (*Language) TokenSymbolsByName ¶
TokenSymbolsByName returns all terminal token symbols whose display name matches name. The returned symbols are in grammar order.
type LexState ¶
type LexState struct {
AcceptToken Symbol // 0 if this state doesn't accept
Skip bool // true if accepted chars are whitespace
Transitions []LexTransition
Default int // default next state (-1 if none)
EOF int // state on EOF (-1 if none)
}
LexState is one state in the table-driven lexer DFA.
type LexTransition ¶
type LexTransition struct {
Lo, Hi rune // inclusive character range
NextState int
// Skip mirrors tree-sitter's SKIP(state): consume the matched rune
// and continue lexing while resetting token start.
Skip bool
}
LexTransition maps a character range to a next state.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer tokenizes source text using a table-driven DFA.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a syntax tree node.
func NewLeafNode ¶
func NewLeafNode(sym Symbol, named bool, startByte, endByte uint32, startPoint, endPoint Point) *Node
NewLeafNode creates a terminal/leaf node.
func NewParentNode ¶
func NewParentNode(sym Symbol, named bool, children []*Node, fieldIDs []FieldID, productionID uint16) *Node
NewParentNode creates a non-terminal node with children. It sets parent pointers on all children and computes byte/point spans from the first and last children. If any child has an error, the parent is marked as having an error too.
func (*Node) ChildByFieldName ¶
ChildByFieldName returns the first child assigned to the given field name, or nil if no child has that field. The Language is needed to resolve field names to IDs. Uses Language.FieldByName for O(1) lookup.
func (*Node) ChildCount ¶
ChildCount returns the number of children (both named and anonymous).
func (*Node) HasError ¶
HasError reports whether this node or any descendant contains a parse error.
func (*Node) IsNamed ¶
IsNamed reports whether this is a named node (as opposed to anonymous syntax like punctuation).
func (*Node) NamedChild ¶
NamedChild returns the i-th named child (skipping anonymous children), or nil if i is out of range.
func (*Node) NamedChildCount ¶
NamedChildCount returns the number of named children.
func (*Node) NextSibling ¶
NextSibling returns the next sibling node, or nil when this is the last child or has no parent.
func (*Node) ParseState ¶
ParseState returns the parser state associated with this node.
func (*Node) PrevSibling ¶
PrevSibling returns the previous sibling node, or nil when this is the first child or has no parent.
func (*Node) StartPoint ¶
StartPoint returns the row/column position where this node begins.
type ParseAction ¶
type ParseAction struct {
Type ParseActionType
State StateID // target state (shift/recover)
Symbol Symbol // reduced symbol (reduce)
ChildCount uint8 // children consumed (reduce)
DynamicPrecedence int16 // precedence (reduce)
ProductionID uint16 // which production (reduce)
Extra bool // is this an extra token (shift)
Repetition bool // is this a repetition (shift)
}
ParseAction is a single parser action from the parse table.
type ParseActionEntry ¶
type ParseActionEntry struct {
Reusable bool
Actions []ParseAction
}
ParseActionEntry is a group of actions for a (state, symbol) pair.
type ParseActionType ¶
type ParseActionType uint8
ParseActionType identifies the kind of parse action.
const ( ParseActionShift ParseActionType = iota ParseActionReduce ParseActionAccept ParseActionRecover )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser reads parse tables from a Language and produces a syntax tree. It supports GLR parsing: when a (state, symbol) pair maps to multiple actions, the parser forks the stack and explores all alternatives in parallel, merging stacks that converge on the same state and picking the highest dynamic-precedence winner for ambiguities.
func (*Parser) Parse ¶
Parse tokenizes and parses source using the built-in DFA lexer, returning a syntax tree. This works for hand-built grammars that provide LexStates. For real grammars that need a custom lexer, use ParseWithTokenSource. If the input is empty, it returns a tree with a nil root.
func (*Parser) ParseIncremental ¶
ParseIncremental re-parses source after edits were applied to oldTree. It reuses unchanged subtrees from the old tree for better performance. Call oldTree.Edit() for each edit before calling this method.
func (*Parser) ParseIncrementalWithTokenSource ¶
func (p *Parser) ParseIncrementalWithTokenSource(source []byte, oldTree *Tree, ts TokenSource) *Tree
ParseIncrementalWithTokenSource is like ParseIncremental but uses a custom token source.
func (*Parser) ParseWithTokenSource ¶
func (p *Parser) ParseWithTokenSource(source []byte, ts TokenSource) *Tree
ParseWithTokenSource parses source using a custom token source. This is used for real grammars where the lexer DFA isn't available as data tables (e.g., Go grammar using go/scanner as a bridge).
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is a single top-level S-expression pattern in a query.
type PointSkippableTokenSource ¶
type PointSkippableTokenSource interface {
ByteSkippableTokenSource
SkipToByteWithPoint(offset uint32, pt Point) Token
}
PointSkippableTokenSource extends ByteSkippableTokenSource with a hint-based skip that avoids recomputing row/column from byte offset. During incremental parsing the reused node already carries its endpoint, so passing it directly eliminates the O(n) offset-to-point scan.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query holds compiled patterns parsed from a tree-sitter .scm query file. It can be executed against a syntax tree to find matching nodes and return captured names.
func NewQuery ¶
NewQuery compiles query source (tree-sitter .scm format) against a language. It returns an error if the query syntax is invalid or references unknown node types or field names.
func (*Query) CaptureNames ¶
CaptureNames returns the list of unique capture names used in the query.
func (*Query) Exec ¶
func (q *Query) Exec(node *Node, lang *Language, source []byte) *QueryCursor
Exec creates a streaming cursor over matches rooted at node.
func (*Query) Execute ¶
func (q *Query) Execute(tree *Tree) []QueryMatch
Execute runs the query against a syntax tree and returns all matches.
func (*Query) ExecuteNode ¶
func (q *Query) ExecuteNode(node *Node, lang *Language, source []byte) []QueryMatch
ExecuteNode runs the query starting from a specific node.
source is required for text predicates (like #eq? / #match?); pass the originating source bytes for correct predicate evaluation.
func (*Query) PatternCount ¶
PatternCount returns the number of patterns in the query.
type QueryCapture ¶
QueryCapture is a single captured node within a match.
type QueryCursor ¶
type QueryCursor struct {
// contains filtered or unexported fields
}
QueryCursor incrementally walks a node subtree and yields matches one by one. It is the streaming counterpart to Query.Execute and avoids materializing all matches up front.
func (*QueryCursor) NextCapture ¶
func (c *QueryCursor) NextCapture() (QueryCapture, bool)
NextCapture yields captures in match order by draining NextMatch results. This is a practical first-pass ordering: captures are returned in each match's capture order, then by subsequent matches in DFS match order.
func (*QueryCursor) NextMatch ¶
func (c *QueryCursor) NextMatch() (QueryMatch, bool)
NextMatch yields the next query match from the cursor.
type QueryMatch ¶
type QueryMatch struct {
PatternIndex int
Captures []QueryCapture
}
QueryMatch represents a successful pattern match with its captures.
type QueryPredicate ¶
type QueryPredicate struct {
// contains filtered or unexported fields
}
QueryPredicate is a post-match constraint attached to a pattern. Supported forms:
- (#eq? @a @b)
- (#eq? @a "literal")
- (#not-eq? @a @b)
- (#not-eq? @a "literal")
- (#match? @a "regex")
- (#not-match? @a "regex")
- (#lua-match? @a "lua-pattern")
- (#any-of? @a "v1" "v2" ...)
- (#not-any-of? @a "v1" "v2" ...)
- (#has-ancestor? @a type ...)
- (#not-has-ancestor? @a type ...)
- (#not-has-parent? @a type ...)
- (#is? ...), (#is-not? ...)
- (#set! key value), (#offset! @cap ...)
type QueryStep ¶
type QueryStep struct {
// contains filtered or unexported fields
}
QueryStep is one matching instruction within a pattern.
type SymbolMetadata ¶
SymbolMetadata holds display information about a symbol.
type Tag ¶
type Tag struct {
Kind string // e.g. "definition.function", "reference.call"
Name string // the captured symbol text
Range Range // full span of the tagged node
NameRange Range // span of the @name capture
}
Tag represents a tagged symbol in source code, extracted by a Tagger. Kind follows tree-sitter convention: "definition.function", "reference.call", etc. Name is the captured symbol text (e.g., the function name).
type Tagger ¶
type Tagger struct {
// contains filtered or unexported fields
}
Tagger extracts symbol definitions and references from source code using tree-sitter tags queries. It is the tagging counterpart to Highlighter.
Tags queries use a convention where captures follow the pattern:
- @name captures the symbol name (e.g., function identifier)
- @definition.X or @reference.X captures the kind
Example query:
(function_declaration name: (identifier) @name) @definition.function (call_expression function: (identifier) @name) @reference.call
func NewTagger ¶
func NewTagger(lang *Language, tagsQuery string, opts ...TaggerOption) (*Tagger, error)
NewTagger creates a Tagger for the given language and tags query.
func (*Tagger) TagIncremental ¶
TagIncremental re-tags source after edits to oldTree. Returns the tags and the new tree for subsequent incremental calls.
type TaggerOption ¶
type TaggerOption func(*Tagger)
TaggerOption configures a Tagger.
func WithTaggerTokenSourceFactory ¶
func WithTaggerTokenSourceFactory(factory func(source []byte) TokenSource) TaggerOption
WithTaggerTokenSourceFactory sets a factory function that creates a TokenSource for each Tag call.
type Token ¶
type Token struct {
Symbol Symbol
Text string
StartByte uint32
EndByte uint32
StartPoint Point
EndPoint Point
}
Token is a lexed token with position info.
type TokenSource ¶
type TokenSource interface {
// Next returns the next token. It should skip whitespace and comments
// as appropriate for the language. Returns a zero-Symbol token at EOF.
Next() Token
}
TokenSource provides tokens to the parser. This interface abstracts over different lexer implementations: the built-in DFA lexer (for hand-built grammars) or custom bridges like GoTokenSource (for real grammars where we can't extract the C lexer DFA).
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree holds a complete syntax tree along with its source text and language.
func (*Tree) Edit ¶
Edit records an edit on this tree. Call this before ParseIncremental to inform the parser which regions changed. The edit adjusts byte offsets and marks overlapping nodes as dirty so the incremental parser knows what to re-parse.
type WalkAction ¶
type WalkAction int
WalkAction controls the tree walk behavior.
const ( // WalkContinue continues the walk to children and siblings. WalkContinue WalkAction = iota // WalkSkipChildren skips the current node's children but continues to siblings. WalkSkipChildren // WalkStop terminates the walk entirely. WalkStop )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
parity_report
command
|
|
|
probe_generic_support
command
|
|
|
ts2go
command
Command ts2go reads a tree-sitter generated parser.c file and outputs a Go source file containing a function that returns a populated *gotreesitter.Language with all extracted parse tables.
|
Command ts2go reads a tree-sitter generated parser.c file and outputs a Go source file containing a function that returns a populated *gotreesitter.Language with all extracted parse tables. |