Versions in this module Expand all Collapse all v0 v0.6.4 Mar 16, 2026 v0.6.3 Mar 15, 2026 v0.6.2 Mar 15, 2026 v0.6.1 Mar 4, 2026 v0.5.4 Mar 3, 2026 v0.5.3 Mar 3, 2026 Changes in this version + const MinCompatibleLanguageVersion + const RuntimeLanguageVersion + var DebugDFA atomic.Bool + var ErrNoLanguage = errors.New("parser has no language configured") + func EnableArenaProfile(enabled bool) + func ResetArenaProfile() + func ResetPerfCounters() + func RunExternalScanner(lang *Language, payload any, lexer *ExternalLexer, validSymbols []bool) bool + func Walk(node *Node, fn func(node *Node, depth int) WalkAction) + type ArenaProfile struct + FullAcquire uint64 + FullNew uint64 + IncrementalAcquire uint64 + IncrementalNew uint64 + func ArenaProfileSnapshot() ArenaProfile + type BoundTree struct + func Bind(tree *Tree) *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 + func (bt *BoundTree) TreeCursor() *TreeCursor + type ByteSkippableTokenSource interface + SkipToByte func(offset uint32) Token + type ExternalLexer struct + func (l *ExternalLexer) Advance(skip bool) + func (l *ExternalLexer) Column() uint32 + func (l *ExternalLexer) GetColumn() uint32 + func (l *ExternalLexer) Lookahead() rune + func (l *ExternalLexer) MarkEnd() + func (l *ExternalLexer) SetResultSymbol(sym Symbol) + type ExternalScanner interface + Create func() any + Deserialize func(payload any, buf []byte) + Destroy func(payload any) + Scan func(payload any, lexer *ExternalLexer, validSymbols []bool) bool + Serialize func(payload any, buf []byte) int + type ExternalScannerState struct + Data []byte + type ExternalVMInstr struct + A int32 + Alt int32 + B int32 + Op ExternalVMOp + 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 uint8 + const ExternalVMOpAdvance + const ExternalVMOpEmit + const ExternalVMOpFail + const ExternalVMOpIfRuneClass + const ExternalVMOpIfRuneEq + const ExternalVMOpIfRuneInRange + const ExternalVMOpJump + const ExternalVMOpMarkEnd + const ExternalVMOpRequireStateEq + const ExternalVMOpRequireValid + const ExternalVMOpSetState + type ExternalVMProgram struct + Code []ExternalVMInstr + MaxSteps int + type ExternalVMRuneClass uint8 + const ExternalVMRuneClassDigit + const ExternalVMRuneClassLetter + const ExternalVMRuneClassNewline + const ExternalVMRuneClassWhitespace + const ExternalVMRuneClassWord + type ExternalVMScanner struct + func MustNewExternalVMScanner(program ExternalVMProgram) *ExternalVMScanner + func NewExternalVMScanner(program ExternalVMProgram) (*ExternalVMScanner, error) + 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 uint16 + type FieldMapEntry struct + ChildIndex uint8 + FieldID FieldID + Inherited bool + type HighlightRange struct + Capture string + EndByte uint32 + StartByte uint32 + type Highlighter struct + func NewHighlighter(lang *Language, highlightQuery string, opts ...HighlighterOption) (*Highlighter, error) + func (h *Highlighter) Highlight(source []byte) []HighlightRange + func (h *Highlighter) HighlightIncremental(source []byte, oldTree *Tree) ([]HighlightRange, *Tree) + type HighlighterOption func(*Highlighter) + func WithTokenSourceFactory(factory func(source []byte) TokenSource) HighlighterOption + type IncrementalParseProfile struct + EntryScratchPeak uint64 + MaxStacksSeen int + NewNodesAllocated uint64 + RecoverHits uint64 + RecoverLookups uint64 + RecoverSearches uint64 + RecoverStateChecks uint64 + RecoverStateSkips uint64 + RecoverSymbolSkips uint64 + ReparseNanos int64 + ReuseCursorNanos int64 + ReusedBytes uint64 + ReusedSubtrees uint64 + type Injection struct + Language string + Node *Node + Ranges []Range + Tree *Tree + type InjectionParser struct + func NewInjectionParser() *InjectionParser + func (ip *InjectionParser) Parse(source []byte, parentLang string) (*InjectionResult, error) + func (ip *InjectionParser) ParseIncremental(source []byte, parentLang string, oldResult *InjectionResult) (*InjectionResult, error) + func (ip *InjectionParser) RegisterInjectionQuery(parentLang string, query string) error + func (ip *InjectionParser) RegisterLanguage(name string, lang *Language) + func (ip *InjectionParser) SetMaxDepth(depth int) + type InjectionResult struct + Injections []Injection + Tree *Tree + type InputEdit struct + NewEndByte uint32 + NewEndPoint Point + OldEndByte uint32 + OldEndPoint Point + StartByte uint32 + StartPoint Point + type Language struct + AliasSequences [][]Symbol + ExternalScanner ExternalScanner + ExternalSymbols []Symbol + ExternalTokenCount uint32 + FieldCount uint32 + FieldMapEntries []FieldMapEntry + FieldMapSlices [][2]uint16 + FieldNames []string + InitialState StateID + KeywordCaptureToken Symbol + KeywordLexStates []LexState + LanguageVersion uint32 + LargeStateCount uint32 + LexModes []LexMode + LexStates []LexState + MaxReservedWordSetSize uint16 + Metadata LanguageMetadata + Name string + ParseActions []ParseActionEntry + ParseTable [][]uint16 + PrimaryStateIDs []StateID + ProductionIDCount uint32 + ReservedWords []Symbol + SmallParseTable []uint16 + SmallParseTableMap []uint32 + StateCount uint32 + SupertypeMapEntries []Symbol + SupertypeMapSlices [][2]uint16 + SupertypeSymbols []Symbol + SymbolCount uint32 + SymbolMetadata []SymbolMetadata + SymbolNames []string + TokenCount uint32 + func (l *Language) CompatibleWithRuntime() bool + func (l *Language) FieldByName(name string) (FieldID, bool) + func (l *Language) IsSupertype(sym Symbol) bool + func (l *Language) SupertypeChildren(sym Symbol) []Symbol + func (l *Language) SymbolByName(name string) (Symbol, bool) + func (l *Language) TokenSymbolsByName(name string) []Symbol + func (l *Language) Version() uint32 + type LanguageMetadata struct + MajorVersion uint8 + MinorVersion uint8 + PatchVersion uint8 + type LexMode struct + ExternalLexState uint16 + LexState uint16 + ReservedWordSetID uint16 + type LexState struct + AcceptToken Symbol + Default int + EOF int + Skip bool + Transitions []LexTransition + type LexTransition struct + Hi rune + Lo rune + NextState int + Skip bool + type Lexer struct + func NewLexer(states []LexState, source []byte) *Lexer + func (l *Lexer) Next(startState uint16) Token + type LookaheadIterator struct + func NewLookaheadIterator(lang *Language, state StateID) (*LookaheadIterator, error) + func (it *LookaheadIterator) CurrentSymbol() Symbol + func (it *LookaheadIterator) CurrentSymbolName() string + func (it *LookaheadIterator) Language() *Language + func (it *LookaheadIterator) Next() bool + func (it *LookaheadIterator) ResetState(state StateID) error + type Node struct + func NewLeafNode(sym Symbol, named bool, startByte, endByte uint32, startPoint, endPoint Point) *Node + func NewParentNode(sym Symbol, named bool, children []*Node, fieldIDs []FieldID, ...) *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) DescendantForByteRange(startByte, endByte uint32) *Node + func (n *Node) DescendantForPointRange(startPoint, endPoint Point) *Node + func (n *Node) EndByte() uint32 + func (n *Node) EndPoint() Point + func (n *Node) FieldNameForChild(i int, lang *Language) string + func (n *Node) HasChanges() bool + func (n *Node) HasError() bool + func (n *Node) IsError() bool + func (n *Node) IsExtra() 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) NamedDescendantForByteRange(startByte, endByte uint32) *Node + func (n *Node) NamedDescendantForPointRange(startPoint, endPoint Point) *Node + func (n *Node) NextSibling() *Node + func (n *Node) Parent() *Node + func (n *Node) ParseState() StateID + func (n *Node) PreGotoState() StateID + func (n *Node) PrevSibling() *Node + func (n *Node) Range() Range + func (n *Node) SExpr(lang *Language) string + 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 struct + ChildCount uint8 + DynamicPrecedence int16 + Extra bool + ProductionID uint16 + Repetition bool + State StateID + Symbol Symbol + Type ParseActionType + type ParseActionEntry struct + Actions []ParseAction + Reusable bool + type ParseActionType uint8 + const ParseActionAccept + const ParseActionRecover + const ParseActionReduce + const ParseActionShift + type ParseOption func(*parseConfig) + func WithOldTree(oldTree *Tree) ParseOption + func WithProfiling() ParseOption + func WithTokenSource(ts TokenSource) ParseOption + type ParseResult struct + Profile IncrementalParseProfile + ProfileAvailable bool + Tree *Tree + type ParseRuntime struct + ExpectedEOFByte uint32 + IterationLimit int + Iterations int + LastTokenEndByte uint32 + LastTokenSymbol Symbol + LastTokenWasEOF bool + MaxStacksSeen int + NodeLimit int + NodesAllocated int + PeakStackDepth int + RootEndByte uint32 + SourceLen uint32 + StackDepthLimit int + StopReason ParseStopReason + TokenSourceEOFEarly bool + TokensConsumed uint64 + Truncated bool + func (rt ParseRuntime) Summary() string + type ParseStopReason string + const ParseStopAccepted + const ParseStopIterationLimit + const ParseStopNoStacksAlive + const ParseStopNodeLimit + const ParseStopNone + const ParseStopStackDepthLimit + const ParseStopTokenSourceEOF + type Parser struct + func NewParser(lang *Language) *Parser + func (p *Parser) IncludedRanges() []Range + func (p *Parser) Parse(source []byte) (*Tree, error) + func (p *Parser) ParseIncremental(source []byte, oldTree *Tree) (*Tree, error) + func (p *Parser) ParseIncrementalProfiled(source []byte, oldTree *Tree) (*Tree, IncrementalParseProfile, error) + func (p *Parser) ParseIncrementalWithTokenSource(source []byte, oldTree *Tree, ts TokenSource) (*Tree, error) + func (p *Parser) ParseIncrementalWithTokenSourceProfiled(source []byte, oldTree *Tree, ts TokenSource) (*Tree, IncrementalParseProfile, error) + func (p *Parser) ParseWith(source []byte, opts ...ParseOption) (ParseResult, error) + func (p *Parser) ParseWithTokenSource(source []byte, ts TokenSource) (*Tree, error) + func (p *Parser) SetIncludedRanges(ranges []Range) + type Pattern struct + type PerfCounters struct + ConflictOther uint64 + ConflictRR uint64 + ConflictRS uint64 + ErrorNodes uint64 + ExtraNodes uint64 + FirstConflictToken uint64 + ForkActionsHist [8]uint64 + ForkCount uint64 + GlobalCapCullDropped uint64 + GlobalCapCulls uint64 + LexBytes uint64 + LexTokens uint64 + MaxConcurrentStacks uint64 + MergeAliveHist [maxGLRStacks + 2]uint64 + MergeCalls uint64 + MergeDeadPruned uint64 + MergeHashZero uint64 + MergeOutHist [maxGLRStacks + 2]uint64 + MergePerKeyOverflow uint64 + MergeReplacements uint64 + MergeStacksInHist [maxGLRStacks + 2]uint64 + ParentChildPointers uint64 + ReduceChainBreakAccept uint64 + ReduceChainBreakMulti uint64 + ReduceChainBreakShift uint64 + ReduceChainMaxLen uint64 + ReduceChainSteps uint64 + ReuseCandidatesChecked uint64 + ReuseLeafSuccesses uint64 + ReuseNodesPopped uint64 + ReuseNodesPushed uint64 + ReuseNodesVisited uint64 + ReuseNonLeafBytes uint64 + ReuseNonLeafChecks uint64 + ReuseNonLeafNoGoto uint64 + ReuseNonLeafNoGotoNt uint64 + ReuseNonLeafNoGotoTerm uint64 + ReuseNonLeafStateMiss uint64 + ReuseNonLeafStateZero uint64 + ReuseNonLeafSuccesses uint64 + ReuseSuccesses uint64 + StackCompareCalls uint64 + StackEqHashMissSkips uint64 + StackEquivalentCalls uint64 + StackEquivalentTrue uint64 + func PerfCountersSnapshot() PerfCounters + type Point struct + Column uint32 + Row uint32 + type PointSkippableTokenSource interface + SkipToByteWithPoint func(offset uint32, pt Point) Token + type Query struct + func NewQuery(source string, lang *Language) (*Query, error) + func (q *Query) CaptureNames() []string + func (q *Query) Exec(node *Node, lang *Language, source []byte) *QueryCursor + func (q *Query) Execute(tree *Tree) []QueryMatch + func (q *Query) ExecuteNode(node *Node, lang *Language, source []byte) []QueryMatch + func (q *Query) PatternCount() int + type QueryCapture struct + Name string + Node *Node + TextOverride string + func (c QueryCapture) Text(source []byte) string + type QueryCursor struct + func (c *QueryCursor) NextCapture() (QueryCapture, bool) + func (c *QueryCursor) NextMatch() (QueryMatch, bool) + func (c *QueryCursor) SetByteRange(startByte, endByte uint32) + func (c *QueryCursor) SetPointRange(startPoint, endPoint Point) + type QueryMatch struct + Captures []QueryCapture + PatternIndex int + func (m QueryMatch) SetValues(q *Query, key string) []string + type QueryPredicate struct + type QueryStep struct + type Range struct + EndByte uint32 + EndPoint Point + StartByte uint32 + StartPoint Point + func DiffChangedRanges(oldTree, newTree *Tree) []Range + type Rewriter struct + func NewRewriter(source []byte) *Rewriter + func (r *Rewriter) Apply() (newSource []byte, edits []InputEdit, err error) + func (r *Rewriter) ApplyToTree(tree *Tree) ([]byte, error) + func (r *Rewriter) Delete(node *Node) + func (r *Rewriter) InsertAfter(node *Node, text []byte) + func (r *Rewriter) InsertBefore(node *Node, text []byte) + func (r *Rewriter) Replace(node *Node, newText []byte) + func (r *Rewriter) ReplaceRange(startByte, endByte uint32, newText []byte) + type StateID uint16 + type Symbol uint16 + type SymbolMetadata struct + Name string + Named bool + Supertype bool + Visible bool + type Tag struct + Kind string + Name string + NameRange Range + Range Range + type Tagger struct + func NewTagger(lang *Language, tagsQuery string, opts ...TaggerOption) (*Tagger, error) + func (tg *Tagger) Tag(source []byte) []Tag + func (tg *Tagger) TagIncremental(source []byte, oldTree *Tree) ([]Tag, *Tree) + func (tg *Tagger) TagTree(tree *Tree) []Tag + type TaggerOption func(*Tagger) + func WithTaggerTokenSourceFactory(factory func(source []byte) TokenSource) TaggerOption + type Token struct + EndByte uint32 + EndPoint Point + StartByte uint32 + StartPoint Point + Symbol Symbol + Text string + type TokenSource interface + Next func() Token + type Tree struct + func NewTree(root *Node, source []byte, lang *Language) *Tree + func (t *Tree) ChangedRanges() []Range + func (t *Tree) Edit(edit InputEdit) + func (t *Tree) Edits() []InputEdit + func (t *Tree) Language() *Language + func (t *Tree) ParseRuntime() ParseRuntime + func (t *Tree) ParseStopReason() ParseStopReason + func (t *Tree) ParseStoppedEarly() bool + func (t *Tree) Release() + func (t *Tree) RootNode() *Node + func (t *Tree) Source() []byte + type TreeCursor struct + func NewTreeCursor(node *Node, tree *Tree) *TreeCursor + func NewTreeCursorFromTree(tree *Tree) *TreeCursor + func (c *TreeCursor) Copy() *TreeCursor + func (c *TreeCursor) CurrentFieldID() FieldID + func (c *TreeCursor) CurrentFieldName() string + func (c *TreeCursor) CurrentNode() *Node + func (c *TreeCursor) CurrentNodeIsNamed() bool + func (c *TreeCursor) CurrentNodeText() string + func (c *TreeCursor) CurrentNodeType() string + func (c *TreeCursor) Depth() int + func (c *TreeCursor) GotoChildByFieldID(fid FieldID) bool + func (c *TreeCursor) GotoChildByFieldName(name string) bool + func (c *TreeCursor) GotoFirstChild() bool + func (c *TreeCursor) GotoFirstChildForByte(targetByte uint32) int64 + func (c *TreeCursor) GotoFirstChildForPoint(targetPoint Point) int64 + func (c *TreeCursor) GotoFirstNamedChild() bool + func (c *TreeCursor) GotoLastChild() bool + func (c *TreeCursor) GotoLastNamedChild() bool + func (c *TreeCursor) GotoNextNamedSibling() bool + func (c *TreeCursor) GotoNextSibling() bool + func (c *TreeCursor) GotoParent() bool + func (c *TreeCursor) GotoPrevNamedSibling() bool + func (c *TreeCursor) GotoPrevSibling() bool + func (c *TreeCursor) Reset(node *Node) + func (c *TreeCursor) ResetTree(tree *Tree) + type WalkAction int + const WalkContinue + const WalkSkipChildren + const WalkStop