Documentation
¶
Index ¶
- Constants
- func DecodeUTF8(s []byte) (int32, uint32)
- func DecodeUTF16BE(s []byte) (int32, uint32)
- func DecodeUTF16LE(s []byte) (int32, uint32)
- func EncodeTables(t *Tables) ([]byte, error)
- func SetContains(ranges []CharacterRange, lookahead int32) bool
- type CharacterRange
- type ExternalScanner
- type FieldID
- type FieldMapEntry
- type Input
- type InputEdit
- type InputEncoding
- type Language
- func (l *Language) AliasAt(productionID uint32, childIndex uint32) Symbol
- func (l *Language) AliasesForSymbol(originalSymbol Symbol) []Symbol
- func (l *Language) FieldIDForName(name string) FieldID
- func (l *Language) FieldNameForID(id FieldID) string
- func (l *Language) LanguageName() string
- func (l *Language) StateIsPrimary(state StateID) bool
- func (l *Language) Subtypes(supertype Symbol) []Symbol
- func (l *Language) Supertypes() []Symbol
- func (l *Language) SymbolCountTotal() uint32
- func (l *Language) SymbolForName(name string, isNamed bool) Symbol
- func (l *Language) SymbolName(symbol Symbol) string
- type LanguageMetadata
- type LexInstr
- type LexOp
- type LexProgram
- type Lexer
- type LexerMode
- type MapSlice
- type Node
- func (n Node) Child(index uint32) Node
- func (n Node) ChildByFieldID(fieldID FieldID) Node
- func (n Node) ChildByFieldName(name string) Node
- func (n Node) ChildCount() uint32
- func (n Node) ChildWithDescendant(descendant Node) Node
- func (n Node) Children() []Node
- func (n Node) DescendantCount() uint32
- func (n Node) DescendantForByteRange(start, end uint32) Node
- func (n Node) DescendantForPointRange(start, end Point) Node
- func (n *Node) Edit(edit InputEdit)
- func (n Node) EndByte() uint32
- func (n Node) EndPoint() Point
- func (n Node) Equal(other Node) bool
- func (n Node) FieldNameForChild(index uint32) string
- func (n Node) FieldNameForNamedChild(index uint32) string
- func (n Node) GrammarSymbol() Symbol
- func (n Node) GrammarType() 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) IsNull() bool
- func (n Node) NamedChild(index uint32) Node
- func (n Node) NamedChildCount() uint32
- func (n Node) NamedChildren() []Node
- func (n Node) NamedDescendantForByteRange(start, end uint32) Node
- func (n Node) NamedDescendantForPointRange(start, end Point) Node
- func (n Node) NextNamedSibling() Node
- func (n Node) NextParseState() StateID
- func (n Node) NextSibling() Node
- func (n Node) Parent() Node
- func (n Node) ParseState() StateID
- func (n Node) PrevNamedSibling() Node
- func (n Node) PrevSibling() Node
- func (n Node) StartByte() uint32
- func (n Node) StartPoint() Point
- func (n Node) String() string
- func (n Node) Symbol() Symbol
- func (n Node) Tree() *Tree
- func (n Node) Type() string
- func (n Node) Walk() *TreeCursor
- type ParseAction
- type ParseActionEntry
- type Parser
- func (p *Parser) IncludedRanges() []Range
- func (p *Parser) Language() *Language
- func (p *Parser) Parse(oldTree *Tree, input Input) *Tree
- func (p *Parser) ParseString(oldTree *Tree, source []byte) *Tree
- func (p *Parser) Reset()
- func (p *Parser) SetIncludedRanges(ranges []Range) bool
- func (p *Parser) SetLanguage(language *Language) bool
- type Point
- type PredicateStep
- type PredicateStepType
- type PropertyPredicate
- type Quantifier
- type Query
- func (q *Query) CaptureCount() int
- func (q *Query) CaptureIndexForName(name string) (uint32, bool)
- func (q *Query) CaptureNameForID(id uint32) string
- func (q *Query) CaptureNames() []string
- func (q *Query) CaptureQuantifierForID(patternIndex, captureIndex uint32) Quantifier
- func (q *Query) CaptureQuantifiers(patternIndex int) []Quantifier
- func (q *Query) Copy() *Query
- func (q *Query) DisableCapture(name string)
- func (q *Query) DisablePattern(patternIndex int)
- func (q *Query) EndByteForPattern(patternIndex int) uint32
- func (q *Query) GeneralPredicates(patternIndex int) []QueryPredicate
- func (q *Query) IsPatternGuaranteedAtStep(byteOffset uint32) bool
- func (q *Query) IsPatternNonLocal(patternIndex int) bool
- func (q *Query) IsPatternRooted(patternIndex int) bool
- func (q *Query) Language() *Language
- func (q *Query) PatternCount() int
- func (q *Query) PredicatesForPattern(patternIndex int) []PredicateStep
- func (q *Query) PropertyPredicates(patternIndex int) []PropertyPredicate
- func (q *Query) PropertySettings(patternIndex int) []QueryProperty
- func (q *Query) StartByteForPattern(patternIndex int) uint32
- func (q *Query) StringCount() int
- func (q *Query) StringValueForID(id uint32) string
- type QueryCapture
- type QueryCursor
- func (c *QueryCursor) Captures(query *Query, node Node, source []byte) iter.Seq2[*QueryMatch, uint32]
- func (c *QueryCursor) CapturesWithOptions(query *Query, node Node, text TextProvider, options *QueryCursorOptions) iter.Seq2[*QueryMatch, uint32]
- func (c *QueryCursor) DidExceedMatchLimit() bool
- func (c *QueryCursor) Exec(query *Query, node Node)
- func (c *QueryCursor) ExecWithOptions(query *Query, node Node, options *QueryCursorOptions)
- func (c *QueryCursor) MatchLimit() uint32
- func (c *QueryCursor) Matches(query *Query, node Node, source []byte) iter.Seq[*QueryMatch]
- func (c *QueryCursor) MatchesWithOptions(query *Query, node Node, text TextProvider, options *QueryCursorOptions) iter.Seq[*QueryMatch]
- func (c *QueryCursor) NextCapture(match *QueryMatch) (uint32, bool)
- func (c *QueryCursor) NextMatch(match *QueryMatch) bool
- func (c *QueryCursor) RemoveMatch(matchID uint32)
- func (c *QueryCursor) SetByteRange(startByte, endByte uint32) bool
- func (c *QueryCursor) SetContainingByteRange(startByte, endByte uint32) bool
- func (c *QueryCursor) SetContainingPointRange(startPoint, endPoint Point) bool
- func (c *QueryCursor) SetMatchLimit(limit uint32)
- func (c *QueryCursor) SetMaxStartDepth(maxStartDepth uint32)
- func (c *QueryCursor) SetPointRange(startPoint, endPoint Point) bool
- type QueryCursorOptions
- type QueryCursorState
- type QueryError
- type QueryErrorKind
- type QueryMatch
- type QueryPredicate
- type QueryPredicateArg
- type QueryPredicateArgKind
- type QueryProperty
- type Range
- type StateID
- type Symbol
- type SymbolMetadata
- type Tables
- type TextProvider
- type Tree
- func (t *Tree) Copy() *Tree
- func (t *Tree) Edit(edit InputEdit)
- func (t *Tree) IncludedRanges() []Range
- func (t *Tree) Language() *Language
- func (t *Tree) RootNode() Node
- func (t *Tree) RootNodeWithOffset(offsetBytes uint32, offsetExtent Point) Node
- func (t *Tree) String() string
- func (t *Tree) Walk() *TreeCursor
- type TreeCursor
- func (c *TreeCursor) Copy() *TreeCursor
- func (c *TreeCursor) Depth() uint32
- func (c *TreeCursor) FieldName() string
- func (c *TreeCursor) GotoFirstChild() bool
- func (c *TreeCursor) GotoNextSibling() bool
- func (c *TreeCursor) GotoParent() bool
- func (c *TreeCursor) GotoPreviousSibling() bool
- func (c *TreeCursor) Node() Node
- func (c *TreeCursor) Reset(n Node)
Constants ¶
const ( ParseActionTypeShift uint8 = iota ParseActionTypeReduce ParseActionTypeAccept ParseActionTypeRecover )
Parse action types.
const ( MinABIVersion = 13 MaxABIVersion = 15 )
A generator must refuse an ABI outside this range: the tables would parse nothing. See checkABI in cmd/ts-translate.
const ( BinOr int32 = iota BinAnd BinBitOr BinXor BinBitAnd BinEq BinNe BinLt BinGt BinLe BinGe BinShl BinShr BinAdd BinSub BinMul BinDiv BinMod )
The binary operators a lex condition uses, as OpBinary's Arg.
Variables ¶
This section is empty.
Functions ¶
func DecodeUTF8 ¶
DecodeUTF8 mirrors the reference implementation's byte sequence handling, including how far it advances over an ill formed sequence.
func DecodeUTF16BE ¶
DecodeUTF16BE decodes a single code point from big endian input.
func DecodeUTF16LE ¶
DecodeUTF16LE decodes a single code point from little endian input.
func EncodeTables ¶
EncodeTables writes a grammar's data as a compressed blob.
func SetContains ¶
func SetContains(ranges []CharacterRange, lookahead int32) bool
SetContains reports whether a code point falls in any of the sorted ranges.
Types ¶
type CharacterRange ¶
CharacterRange is an inclusive range of code points.
type ExternalScanner ¶
type ExternalScanner interface {
Create() any
Destroy(payload any)
Scan(payload any, lexer *Lexer, validSymbols []bool) bool
Serialize(payload any, buffer []byte) uint32
Deserialize(payload any, buffer []byte)
}
ExternalScanner is the set of callbacks a hand written scanner provides.
type FieldMapEntry ¶
FieldMapEntry associates a field name with a child position.
type Input ¶
type Input struct {
Read func(byteOffset uint32, position Point) []byte
Encoding InputEncoding
Decode func([]byte) (int32, uint32)
}
Input supplies source text to the parser in chunks.
type InputEdit ¶
type InputEdit struct {
StartByte uint32
OldEndByte uint32
NewEndByte uint32
StartPoint Point
OldEndPoint Point
NewEndPoint Point
}
InputEdit describes a change to a document.
type InputEncoding ¶
type InputEncoding int
InputEncoding selects how the source bytes are decoded.
const ( EncodingUTF8 InputEncoding = iota EncodingUTF16LE EncodingUTF16BE EncodingCustom )
Supported source encodings.
type Language ¶
type Language struct {
ABIVersion uint32
SymbolCount uint32
AliasCount uint32
TokenCount uint32
ExternalTokenCount uint32
StateCount uint32
LargeStateCount uint32
ProductionIDCount uint32
FieldCount uint32
MaxAliasSequenceLen uint16
ParseTable []uint16
SmallParseTable []uint16
SmallParseTableMap []uint32
ParseActions []ParseActionEntry
SymbolNames []string
FieldNames []string
FieldMapSlices []MapSlice
FieldMapEntries []FieldMapEntry
SymbolMetadataTable []SymbolMetadata
PublicSymbolMap []Symbol
AliasMap []uint16
AliasSequences []Symbol
LexModes []LexerMode
LexFn func(*Lexer, StateID) bool
KeywordLexFn func(*Lexer, StateID) bool
KeywordCaptureToken Symbol
ExternalScannerStates []bool
ExternalScannerSymbol []Symbol
Scanner ExternalScanner
PrimaryStateIDs []StateID
Name string
ReservedWords []Symbol
MaxReservedWordSetLen uint16
SupertypeCount uint32
SupertypeSymbols []Symbol
SupertypeMapSlices []MapSlice
SupertypeMapEntries []Symbol
Metadata LanguageMetadata
}
Language holds a grammar's parse tables and lexer functions.
func LoadGrammar ¶
func LoadGrammar(name string, blob []byte, scanner ExternalScanner) *Language
LoadGrammar decodes a grammar's table blob and wires its lexer. Pass a nil scanner for a grammar with no external tokens.
It panics on a blob this runtime cannot read. A grammar that parses nothing is worse to hand back than a stop at the point the fault is visible.
func (*Language) AliasesForSymbol ¶
AliasesForSymbol reports every public name a symbol can take.
func (*Language) FieldIDForName ¶
FieldIDForName returns the identifier of a named field.
func (*Language) FieldNameForID ¶
FieldNameForID returns a field's name.
func (*Language) LanguageName ¶
LanguageName reports the grammar's own name.
func (*Language) StateIsPrimary ¶
StateIsPrimary reports whether a state is the canonical any of its class.
func (*Language) Supertypes ¶
Supertypes reports the grammar's supertype symbols.
func (*Language) SymbolCountTotal ¶
SymbolCountTotal reports the number of symbols including aliases.
func (*Language) SymbolForName ¶
SymbolForName finds a symbol by its display name.
func (*Language) SymbolName ¶
SymbolName returns the display name for a symbol.
type LanguageMetadata ¶
LanguageMetadata is a grammar's semantic version.
type LexOp ¶
type LexOp uint8
LexOp is a single instruction of a lexer program.
const ( // OpPushLit pushes Arg. OpPushLit LexOp = iota // OpPushLookahead pushes the code point at the current position. OpPushLookahead // OpPushEOF pushes the end-of-input flag this iteration read. OpPushEOF // OpPushSet pushes whether character set Arg holds the lookahead. OpPushSet // OpNot and OpNeg replace the top of the stack. OpNot OpNeg // OpBinary combines the top values with binary operator Arg. OpBinary // OpJumpIfFalse pops, and jumps to Arg when the value is empty. OpJumpIfFalse // OpDispatch jumps to the body of the case for the current state. OpDispatch // OpAdvance and OpSkip move to state Arg. Skip drops what it consumed. OpAdvance OpSkip // OpAdvanceMap reads map Arg, and advances on a lookahead the map names. OpAdvanceMap // OpAccept marks the token Arg, ending here. OpAccept // OpEnd answers with what the run accepted. OpReturn answers Arg. OpEnd OpReturn // OpReadEOF reads the end-of-input flag. OpReadEOF )
type LexProgram ¶
LexProgram is a lexer state machine. Code opens with the prologue and an OpDispatch, and the case bodies follow it.
func (*LexProgram) Run ¶
func (p *LexProgram) Run(sets [][]CharacterRange, lexer *Lexer, state StateID) bool
Run walks the program for a single token.
type Lexer ¶
type Lexer struct {
// Lookahead is the code point at the current position.
Lookahead int32
// ResultSymbol is set by a lex function when it accepts a token.
ResultSymbol Symbol
// contains filtered or unexported fields
}
Lexer scans the source text on behalf of a grammar's lex functions.
func (*Lexer) IsAtIncludedRangeStart ¶
IsAtIncludedRangeStart reports whether the lexer sits on a range boundary.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a single node in a syntax tree.
func (Node) ChildByFieldID ¶
ChildByFieldID returns the child registered under the given field.
func (Node) ChildByFieldName ¶
ChildByFieldName returns the child registered under the given field name.
func (Node) ChildCount ¶
ChildCount reports the number of visible children.
func (Node) ChildWithDescendant ¶
ChildWithDescendant returns the child that contains the given descendant.
func (Node) Children ¶
Children returns every visible child, as Child returns each. It reads the children once.
func (Node) DescendantCount ¶
DescendantCount reports how many visible nodes the subtree holds.
func (Node) DescendantForByteRange ¶
DescendantForByteRange returns the smallest node spanning the byte range.
func (Node) DescendantForPointRange ¶
DescendantForPointRange returns the smallest node spanning the point range.
func (Node) FieldNameForChild ¶
FieldNameForChild reports the field name of the visible child at an index.
func (Node) FieldNameForNamedChild ¶
FieldNameForNamedChild reports the field name of the named child at an index.
func (Node) GrammarSymbol ¶
GrammarSymbol reports the node's symbol before alias resolution.
func (Node) GrammarType ¶
GrammarType reports the node's rule name before alias resolution.
func (Node) HasChanges ¶
HasChanges reports whether an edit touched the node.
func (Node) NamedChild ¶
NamedChild returns the named child at the given index.
func (Node) NamedChildCount ¶
NamedChildCount reports the number of named children.
func (Node) NamedChildren ¶
NamedChildren returns every named child, as NamedChild returns each.
func (Node) NamedDescendantForByteRange ¶
NamedDescendantForByteRange returns the smallest named node spanning the range.
func (Node) NamedDescendantForPointRange ¶
NamedDescendantForPointRange returns the smallest named node spanning the range.
func (Node) NextNamedSibling ¶
NextNamedSibling returns the next named node with the same parent.
func (Node) NextParseState ¶
NextParseState reports the state reached after the node.
func (Node) NextSibling ¶
NextSibling returns the next visible node with the same parent.
func (Node) ParseState ¶
ParseState reports the parse state the node was created in.
func (Node) PrevNamedSibling ¶
PrevNamedSibling returns the named node with the same parent.
func (Node) PrevSibling ¶
PrevSibling returns the visible node with the same parent.
func (Node) StartPoint ¶
StartPoint reports the node's earliest row and column.
type ParseAction ¶
type ParseAction struct {
Type uint8
State StateID
Extra bool
Repetition bool
ChildCount uint8
Symbol Symbol
DynamicPrecedence int16
ProductionID uint16
}
ParseAction is a single entry of a parse table cell.
type ParseActionEntry ¶
type ParseActionEntry struct {
Action ParseAction
Count uint8
Reusable bool
}
ParseActionEntry is either a group header or a single action.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser turns source text into a syntax tree.
func (*Parser) IncludedRanges ¶
IncludedRanges reports the regions the parser reads.
func (*Parser) ParseString ¶
ParseString builds a syntax tree from a source string.
func (*Parser) Reset ¶
func (p *Parser) Reset()
Reset clears any parse state left over from a previous call.
func (*Parser) SetIncludedRanges ¶
SetIncludedRanges restricts parsing to the given regions.
func (*Parser) SetLanguage ¶
SetLanguage assigns the grammar this parser uses.
type PredicateStep ¶
type PredicateStep struct {
Type PredicateStepType
ValueID uint32
}
PredicateStep is one token of a predicate, as TSQueryPredicateStep. A Capture step's ValueID is a capture id.
type PredicateStepType ¶
type PredicateStepType uint8
PredicateStepType says what a predicate step holds. The values follow. TSQueryPredicateStepType.
const ( PredicateStepDone PredicateStepType = iota PredicateStepCapture PredicateStepString )
The step types. A Done step ends one predicate.
type PropertyPredicate ¶
type PropertyPredicate struct {
Property QueryProperty
Positive bool
}
PropertyPredicate is a property paired with whether it was `#is?` (true) or `#is-not?` (false).
type Quantifier ¶
type Quantifier uint8
Quantifier says how many times a capture can appear in a pattern. The values follow TSQuantifier.
const ( QuantifierZero Quantifier = iota QuantifierZeroOrOne QuantifierZeroOrMore QuantifierOne QuantifierOneOrMore )
The quantifiers a capture can carry.
func (Quantifier) String ¶
func (q Quantifier) String() string
String names the quantifier the way the Rust binding's CaptureQuantifier does.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a TSQuery: patterns compiled from S-expressions. A Query is immutable during execution, so cursors can share it.
func NewQuery ¶
NewQuery is ts_query_new, plus the predicate parsing the Rust binding's Query::new performs. The error is a *QueryError.
func (*Query) CaptureCount ¶
CaptureCount is ts_query_capture_count.
func (*Query) CaptureIndexForName ¶
CaptureIndexForName reports the capture id of a name, as the Rust binding's capture_index_for_name.
func (*Query) CaptureNameForID ¶
CaptureNameForID is ts_query_capture_name_for_id.
func (*Query) CaptureNames ¶
CaptureNames reports every capture name, indexed by capture id.
func (*Query) CaptureQuantifierForID ¶
func (q *Query) CaptureQuantifierForID(patternIndex, captureIndex uint32) Quantifier
CaptureQuantifierForID is ts_query_capture_quantifier_for_id.
func (*Query) CaptureQuantifiers ¶
func (q *Query) CaptureQuantifiers(patternIndex int) []Quantifier
CaptureQuantifiers reports a pattern's quantifier for every capture id, as the Rust binding's capture_quantifiers.
func (*Query) Copy ¶
Copy is ts_query_copy: an independent query to disable captures or patterns on.
func (*Query) DisableCapture ¶
DisableCapture is ts_query_disable_capture.
func (*Query) DisablePattern ¶
DisablePattern is ts_query_disable_pattern.
func (*Query) EndByteForPattern ¶
EndByteForPattern is ts_query_end_byte_for_pattern.
func (*Query) GeneralPredicates ¶
func (q *Query) GeneralPredicates(patternIndex int) []QueryPredicate
GeneralPredicates reports the predicates of a pattern that the library leaves to the caller, as the Rust binding's general_predicates.
func (*Query) IsPatternGuaranteedAtStep ¶
IsPatternGuaranteedAtStep is ts_query_is_pattern_guaranteed_at_step.
func (*Query) IsPatternNonLocal ¶
IsPatternNonLocal is ts_query_is_pattern_non_local.
func (*Query) IsPatternRooted ¶
IsPatternRooted is ts_query_is_pattern_rooted.
func (*Query) PatternCount ¶
PatternCount is ts_query_pattern_count.
func (*Query) PredicatesForPattern ¶
func (q *Query) PredicatesForPattern(patternIndex int) []PredicateStep
PredicatesForPattern is ts_query_predicates_for_pattern. Each predicate ends with a Done step.
func (*Query) PropertyPredicates ¶
func (q *Query) PropertyPredicates(patternIndex int) []PropertyPredicate
PropertyPredicates reports a pattern's `#is?` and `#is-not?` properties, as the Rust binding's property_predicates.
func (*Query) PropertySettings ¶
func (q *Query) PropertySettings(patternIndex int) []QueryProperty
PropertySettings reports a pattern's `#set!` properties, as the Rust binding's property_settings.
func (*Query) StartByteForPattern ¶
StartByteForPattern is ts_query_start_byte_for_pattern.
func (*Query) StringValueForID ¶
StringValueForID is ts_query_string_value_for_id.
type QueryCapture ¶
QueryCapture is a node a pattern captured, as TSQueryCapture. Index is the capture id, for CaptureNameForID.
type QueryCursor ¶
type QueryCursor struct {
// contains filtered or unexported fields
}
QueryCursor is a TSQueryCursor: it executes one query over one tree at a time, and can be reused across executions.
func (*QueryCursor) Captures ¶
func (c *QueryCursor) Captures(query *Query, node Node, source []byte) iter.Seq2[*QueryMatch, uint32]
Captures runs the query over the node and yields each capture in document order. Those Captures are with its match and its index in the match's captures, as QueryCursor::captures.
func (*QueryCursor) CapturesWithOptions ¶
func (c *QueryCursor) CapturesWithOptions(query *Query, node Node, text TextProvider, options *QueryCursorOptions) iter.Seq2[*QueryMatch, uint32]
CapturesWithOptions is QueryCursor::captures_with_options.
func (*QueryCursor) DidExceedMatchLimit ¶
func (c *QueryCursor) DidExceedMatchLimit() bool
DidExceedMatchLimit is ts_query_cursor_did_exceed_match_limit.
func (*QueryCursor) Exec ¶
func (c *QueryCursor) Exec(query *Query, node Node)
Exec is ts_query_cursor_exec: it starts the query over the node's subtree.
func (*QueryCursor) ExecWithOptions ¶
func (c *QueryCursor) ExecWithOptions(query *Query, node Node, options *QueryCursorOptions)
ExecWithOptions is ts_query_cursor_exec_with_options.
func (*QueryCursor) MatchLimit ¶
func (c *QueryCursor) MatchLimit() uint32
MatchLimit is ts_query_cursor_match_limit.
func (*QueryCursor) Matches ¶
func (c *QueryCursor) Matches(query *Query, node Node, source []byte) iter.Seq[*QueryMatch]
Matches runs the query over the node and yields each match whose text predicates hold, as QueryCursor::matches. The yielded match is valid until the next one.
func (*QueryCursor) MatchesWithOptions ¶
func (c *QueryCursor) MatchesWithOptions(query *Query, node Node, text TextProvider, options *QueryCursorOptions) iter.Seq[*QueryMatch]
MatchesWithOptions is QueryCursor::matches_with_options.
func (*QueryCursor) NextCapture ¶
func (c *QueryCursor) NextCapture(match *QueryMatch) (uint32, bool)
NextCapture is ts_query_cursor_next_capture. It returns captures in document order, which can come from a match that has not finished yet. The index names the capture in the match's list.
func (*QueryCursor) NextMatch ¶
func (c *QueryCursor) NextMatch(match *QueryMatch) bool
NextMatch is ts_query_cursor_next_match. The match's captures alias the cursor's storage and are valid until the next call.
func (*QueryCursor) RemoveMatch ¶
func (c *QueryCursor) RemoveMatch(matchID uint32)
RemoveMatch is ts_query_cursor_remove_match: no more captures of the match are returned.
func (*QueryCursor) SetByteRange ¶
func (c *QueryCursor) SetByteRange(startByte, endByte uint32) bool
SetByteRange is ts_query_cursor_set_byte_range. An end of zero means the end of the document. It reports false for a start past the end.
func (*QueryCursor) SetContainingByteRange ¶
func (c *QueryCursor) SetContainingByteRange(startByte, endByte uint32) bool
SetContainingByteRange is ts_query_cursor_set_containing_byte_range: only a match whose nodes lie within the range is returned.
func (*QueryCursor) SetContainingPointRange ¶
func (c *QueryCursor) SetContainingPointRange(startPoint, endPoint Point) bool
SetContainingPointRange is ts_query_cursor_set_containing_point_range.
func (*QueryCursor) SetMatchLimit ¶
func (c *QueryCursor) SetMatchLimit(limit uint32)
SetMatchLimit is ts_query_cursor_set_match_limit.
func (*QueryCursor) SetMaxStartDepth ¶
func (c *QueryCursor) SetMaxStartDepth(maxStartDepth uint32)
SetMaxStartDepth is ts_query_cursor_set_max_start_depth.
func (*QueryCursor) SetPointRange ¶
func (c *QueryCursor) SetPointRange(startPoint, endPoint Point) bool
SetPointRange is ts_query_cursor_set_point_range.
type QueryCursorOptions ¶
type QueryCursorOptions struct {
Payload any
ProgressCallback func(state *QueryCursorState) bool
}
QueryCursorOptions is a TSQueryCursorOptions. ProgressCallback runs after a bounded amount of work.
type QueryCursorState ¶
QueryCursorState is a TSQueryCursorState: what a progress callback sees.
type QueryError ¶
type QueryError struct {
Kind QueryErrorKind
Offset int
Row int
Column int
Message string
}
QueryError reports why a query did not compile. Offset is the byte offset ts_query_new reports.
func (*QueryError) Error ¶
func (e *QueryError) Error() string
Error renders the error the way the Rust binding's Display does.
type QueryErrorKind ¶
type QueryErrorKind int
QueryErrorKind says which rule a query broke. The values follow TSQueryError.
const ( QueryErrorNone QueryErrorKind = iota QueryErrorSyntax QueryErrorNodeType QueryErrorField QueryErrorCapture QueryErrorStructure QueryErrorLanguage QueryErrorPredicate )
The error kinds a query compile can report. QueryErrorPredicate comes from the predicate layer the Rust binding adds; the others come from ts_query_new.
func (QueryErrorKind) String ¶
func (k QueryErrorKind) String() string
String names the kind the way the Rust binding's QueryErrorKind does.
type QueryMatch ¶
type QueryMatch struct {
ID uint32
PatternIndex uint16
Captures []QueryCapture
}
QueryMatch is one match of a pattern, as TSQueryMatch. Captures aliases a list the cursor owns: it is valid until the cursor's next call.
func (*QueryMatch) NodesForCaptureIndex ¶
func (m *QueryMatch) NodesForCaptureIndex(captureIndex uint32) iter.Seq[Node]
NodesForCaptureIndex reports the nodes a match captured under one capture id, as QueryMatch::nodes_for_capture_index.
func (*QueryMatch) SatisfiesTextPredicates ¶
func (m *QueryMatch) SatisfiesTextPredicates(query *Query, text TextProvider) bool
SatisfiesTextPredicates is QueryMatch::satisfies_text_predicates: whether the text predicates of the match's pattern hold.
type QueryPredicate ¶
type QueryPredicate struct {
Operator string
Args []QueryPredicateArg
}
QueryPredicate is a QueryPredicate: a predicate the library does not interpret, handed to the caller as data.
type QueryPredicateArg ¶
type QueryPredicateArg struct {
Kind QueryPredicateArgKind
CaptureIndex uint32
Value string
}
QueryPredicateArg is a QueryPredicateArg.
type QueryPredicateArgKind ¶
type QueryPredicateArgKind uint8
QueryPredicateArgKind says what a general predicate's argument is.
const ( QueryPredicateArgCapture QueryPredicateArgKind = iota QueryPredicateArgString )
The argument kinds, as QueryPredicateArg.
type QueryProperty ¶
QueryProperty is a QueryProperty. A property with no value has HasValue false.
type Symbol ¶
type Symbol = uint16
Symbol identifies a terminal or non-terminal in a grammar.
const BuiltinSymEnd Symbol = 0
BuiltinSymEnd is the symbol for the end of input.
const BuiltinSymError Symbol = 0xFFFF
BuiltinSymError is the symbol for an error node.
type SymbolMetadata ¶
SymbolMetadata records how a symbol appears in a tree.
type Tables ¶
type Tables struct {
Language
// CharacterSets holds the sets the lexer searches.
CharacterSets [][]CharacterRange
// Lex and KeywordLex are the grammar's lexer state machines.
Lex *LexProgram
KeywordLex *LexProgram
}
The embedded Language's function fields and its scanner are not encoded.
func DecodeTables ¶
DecodeTables reads back what EncodeTables wrote.
type TextProvider ¶
TextProvider returns the text of a node, as the Rust binding's TextProvider.
func SourceText ¶
func SourceText(source []byte) TextProvider
SourceText is the TextProvider over a whole document.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a syntax tree produced by a parser.
func (*Tree) IncludedRanges ¶
IncludedRanges reports the regions the parser read.
func (*Tree) RootNodeWithOffset ¶
RootNodeWithOffset returns the root shifted by the given offset.
func (*Tree) Walk ¶
func (t *Tree) Walk() *TreeCursor
Walk returns a cursor positioned on the tree's root.
type TreeCursor ¶
type TreeCursor struct {
// contains filtered or unexported fields
}
TreeCursor walks a syntax tree. A step to a sibling costs the same at any index, because each level reads its children once.
func (*TreeCursor) Copy ¶
func (c *TreeCursor) Copy() *TreeCursor
Copy returns an independent cursor at the same position.
func (*TreeCursor) Depth ¶
func (c *TreeCursor) Depth() uint32
Depth reports how far the cursor has descended from its starting node.
func (*TreeCursor) FieldName ¶
func (c *TreeCursor) FieldName() string
FieldName reports the field the current node fills in its parent.
func (*TreeCursor) GotoFirstChild ¶
func (c *TreeCursor) GotoFirstChild() bool
GotoFirstChild moves to the earliest visible child, reporting whether a single exists.
func (*TreeCursor) GotoNextSibling ¶
func (c *TreeCursor) GotoNextSibling() bool
GotoNextSibling moves to the next visible sibling, reporting whether a single exists.
func (*TreeCursor) GotoParent ¶
func (c *TreeCursor) GotoParent() bool
GotoParent moves to the parent node, reporting whether a single exists.
func (*TreeCursor) GotoPreviousSibling ¶
func (c *TreeCursor) GotoPreviousSibling() bool
GotoPreviousSibling moves to the visible sibling.
func (*TreeCursor) Node ¶
func (c *TreeCursor) Node() Node
Node reports the node the cursor sits on.
func (*TreeCursor) Reset ¶
func (c *TreeCursor) Reset(n Node)
Reset moves the cursor to the given node and forgets its history.
Source Files
¶
- cursor.go
- grammar.go
- language.go
- length.go
- lexer.go
- lexprog.go
- lookahead.go
- node_core.go
- node_search.go
- parser_core.go
- parser_lex.go
- parser_loop.go
- parser_recover.go
- parser_reduce.go
- query.go
- query_analysis_state.go
- query_analysis_walk.go
- query_analyze.go
- query_api.go
- query_cursor.go
- query_cursor_advance.go
- query_cursor_next.go
- query_cursor_states.go
- query_parse.go
- query_predicate.go
- query_quantifier.go
- query_tree_cursor.go
- ranges.go
- reusable.go
- stack.go
- subtree_core.go
- subtree_edit.go
- subtree_inline.go
- tables.go
- tree.go
- unicode.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ts-fetch
command
Command ts-fetch puts a grammar's upstream sources where ts-translate can read them.
|
Command ts-fetch puts a grammar's upstream sources where ts-translate can read them. |
|
ts-goldens
command
Command ts-goldens records reference results with the upstream tree-sitter command line tool.
|
Command ts-goldens records reference results with the upstream tree-sitter command line tool. |
|
ts-translate
command
Command ts-translate turns a tree-sitter generated parser.c into the table blob a grammar package embeds, and the loader that embeds it.
|
Command ts-translate turns a tree-sitter generated parser.c into the table blob a grammar package embeds, and the loader that embeds it. |
|
grammars
|
|
|
clang
Package clang holds the tree-sitter grammar for the C language.
|
Package clang holds the tree-sitter grammar for the C language. |
|
golang
Package golang holds the tree-sitter grammar for the Go language.
|
Package golang holds the tree-sitter grammar for the Go language. |
|
tsx
Package tsx is TypeScript with JSX.
|
Package tsx is TypeScript with JSX. |
|
internal
|
|
|
corpus
Package corpus reads the test corpus format that every tree-sitter grammar repository ships under test/corpus.
|
Package corpus reads the test corpus format that every tree-sitter grammar repository ships under test/corpus. |
|
goldens
Package goldens compares parse results against files produced by the reference tree-sitter command line tool.
|
Package goldens compares parse results against files produced by the reference tree-sitter command line tool. |
|
grammarsrc
Package grammarsrc puts a grammar's upstream sources where a translator can read them.
|
Package grammarsrc puts a grammar's upstream sources where a translator can read them. |
|
querygoldens
Package querygoldens compares query results against files the reference tree-sitter command line tool wrote with `tree-sitter query`.
|
Package querygoldens compares query results against files the reference tree-sitter command line tool wrote with `tree-sitter query`. |