Documentation
¶
Index ¶
- Constants
- func CalleePath(callNode *ASTNode) string
- func DetectLanguageName(filename string) (string, error)
- func DetectRules(srcPath, dstPath string) *rules.Rules
- func DetectSignificantWhitespace(srcPath, dstPath string) bool
- func DumpAST(w io.Writer, root *ASTNode) error
- func DumpCST(w io.Writer, nodes []FlatNode, symbols []string, src []byte) error
- func GetNativeLanguage(langName string) (unsafe.Pointer, error)
- func IsWordChar(c byte) bool
- func NativeLanguageSymbols(tsLangPtr unsafe.Pointer) []string
- type ASTIndex
- type ASTNode
- func IngestFlatAST(nodes []FlatNode, symbols []string, src []byte, langName string) *ASTNode
- func Parse(src []byte, filename string) (*ASTNode, error)
- func ParseWithLanguage(src []byte, langName string) (*ASTNode, error)
- func ParseWithNativeFlatBuffer(src []byte, tsLangPtr unsafe.Pointer, langName string, symbols []string) (*ASTNode, error)
- func (n *ASTNode) ChildIndex() int
- func (n *ASTNode) ComputeHashes()
- func (n *ASTNode) Contains(candidate *ASTNode) bool
- func (n *ASTNode) DepthTo(ancestor *ASTNode) int
- func (n *ASTNode) Descendants() []*ASTNode
- func (n *ASTNode) EnclosingContainerDeclaration(r *rules.Rules) *ASTNode
- func (n *ASTNode) FrequencyInSubtree(label string) int
- func (n *ASTNode) GetLanguage() string
- func (n *ASTNode) IsAnonymous() bool
- func (n *ASTNode) IsBlock() bool
- func (n *ASTNode) IsBracketOrParen() bool
- func (n *ASTNode) IsCaseClause() bool
- func (n *ASTNode) IsComment() bool
- func (n *ASTNode) IsLeafOrStringLiteral() bool
- func (n *ASTNode) IsScaffolding() bool
- func (n *ASTNode) IsStatement() bool
- func (n *ASTNode) IsWrapper() bool
- func (n *ASTNode) LeafLabels() map[string]int
- func (n *ASTNode) Leaves() []*ASTNode
- func (n *ASTNode) LevelOrder() []*ASTNode
- func (n *ASTNode) PostOrder() []*ASTNode
- func (n *ASTNode) PreOrder() []*ASTNode
- func (n *ASTNode) Root() *ASTNode
- func (n *ASTNode) Size() int
- func (n *ASTNode) SyntaxTrivia() *SyntaxTriviaBlock
- type CommentBlock
- type FlatASTResult
- type FlatNode
- type Language
- type SyntaxTriviaBlock
Constants ¶
const ( FlatNodeNamed = 1 << 0 FlatNodeError = 1 << 1 FlatNodeMissing = 1 << 2 FlatNodeNone = ^uint32(0) )
Variables ¶
This section is empty.
Functions ¶
func CalleePath ¶ added in v0.9.0
CalleePath extracts the canonical dotted identifier path from a call node's function receiver. For selector expressions (os.Exit), it walks leaf tokens and joins with dots. For scoped identifiers (std::process::exit), it normalizes :: to dots. For bare identifiers (exit, panic), it returns the identifier directly.
func DetectLanguageName ¶ added in v0.8.0
DetectLanguageName returns the canonical language name string for a given filename or path.
func DetectRules ¶ added in v0.15.0
DetectRules returns the language rules for srcPath, falling back to dstPath.
func DetectSignificantWhitespace ¶ added in v0.15.0
DetectSignificantWhitespace reports whether the language detected from srcPath (falling back to dstPath) has block scoping defined by leading indentation (e.g. Python). Unknown grammars default conservatively to true.
func DumpAST ¶ added in v0.8.0
DumpAST writes a formatted plain-text Unicode tree representation of an ASTNode to w.
func DumpCST ¶ added in v0.8.0
DumpCST writes a formatted plain-text Unicode tree representation of the raw Tree-sitter flat buffer nodes (Concrete Syntax Tree) to w.
func GetNativeLanguage ¶ added in v0.8.0
GetNativeLanguage retrieves the statically linked native Tree-sitter language for any of the 10 core languages (11 grammars).
func IsWordChar ¶ added in v0.4.0
IsWordChar checks if c is an ASCII letter, digit, or underscore.
func NativeLanguageSymbols ¶ added in v0.8.0
NativeLanguageSymbols returns the slice of symbol names defined by the native Tree-sitter language.
Types ¶
type ASTIndex ¶ added in v0.4.0
type ASTIndex struct {
Nodes []*ASTNode
PostOrder []*ASTNode
LabelIndex map[string][]int32
SyntaxTrivia []SyntaxTriviaBlock // Indexed by ASTNode.ID; kept out of ASTNode to protect its 240-byte cache footprint.
}
ASTIndex holds pre-order and post-order arrays for fast subtree lookups.
func EnsureIndex ¶ added in v0.4.0
EnsureIndex indexes the tree if it hasn't been indexed yet.
type ASTNode ¶
type ASTNode struct {
Type string
Label string
Children []*ASTNode
Parent *ASTNode
StartByte uint32
EndByte uint32
StartRow uint32 // 0-indexed
StartCol uint32
EndRow uint32
EndCol uint32
Language string // Set on root node only
HasError bool // True if parse tree contained any ERROR nodes
ParseErrorCount int // Total count of ERROR nodes in parse tree
IsKeyword bool // True if node is a keyword token
IsUnordered bool // True if children of this container node are order-insensitive
LeadingTrivia []*CommentBlock
TrailingTrivia []*CommentBlock
DanglingTrivia []*CommentBlock
// Hash is the combined hash of node type, label, and children.
Hash uint64
// StructureHash is the shape hash, ignoring leaf labels.
StructureHash uint64
ID int32
PreSize int32
PostStart int32
Index *ASTIndex
}
func IngestFlatAST ¶ added in v0.8.0
IngestFlatAST converts the flat node buffer into a full ASTNode tree, applying language rules, labels, and subtree hashes.
func Parse ¶
Parse detects the language for the given filename and parses source bytes into an ASTNode.
func ParseWithLanguage ¶ added in v0.4.0
ParseWithLanguage parses source bytes for a given language name.
func ParseWithNativeFlatBuffer ¶ added in v0.8.0
func ParseWithNativeFlatBuffer(src []byte, tsLangPtr unsafe.Pointer, langName string, symbols []string) (*ASTNode, error)
ParseWithNativeFlatBuffer parses source code using the native Tree-sitter engine and converts the resulting flat buffer into an ASTNode tree.
func (*ASTNode) ChildIndex ¶ added in v0.4.0
ChildIndex returns the node's position among its parent's children, or -1 if it has no parent.
func (*ASTNode) ComputeHashes ¶ added in v0.4.0
func (n *ASTNode) ComputeHashes()
ComputeHashes fills Hash and StructureHash for the node and its children.
func (*ASTNode) DepthTo ¶ added in v0.5.0
DepthTo returns the number of parent edges between n and ancestor (or 0 if n is ancestor or ancestor is nil).
func (*ASTNode) Descendants ¶ added in v0.4.0
Descendants returns all child nodes under n in pre-order.
func (*ASTNode) EnclosingContainerDeclaration ¶ added in v0.9.0
EnclosingContainerDeclaration walks up from n to find the nearest enclosing function, class, struct, or closure (lambda / anonymous function).
func (*ASTNode) FrequencyInSubtree ¶ added in v0.4.0
FrequencyInSubtree returns how many times a leaf label appears in n's subtree.
func (*ASTNode) GetLanguage ¶
GetLanguage walks up to the root to retrieve the AST's language.
func (*ASTNode) IsAnonymous ¶ added in v0.11.0
IsAnonymous reports whether n is an unnamed syntax token like punctuation or a delimiter.
func (*ASTNode) IsBracketOrParen ¶ added in v0.4.0
IsBracketOrParen reports whether the node label is a bracket, brace, or parenthesis.
func (*ASTNode) IsCaseClause ¶ added in v0.10.0
IsCaseClause reports whether the node is a switch/match/select case clause.
func (*ASTNode) IsComment ¶ added in v0.15.0
IsComment reports whether the node represents a comment in the language grammar.
func (*ASTNode) IsLeafOrStringLiteral ¶ added in v0.4.0
IsLeafOrStringLiteral checks if n is a leaf node or string literal.
func (*ASTNode) IsScaffolding ¶
IsScaffolding reports whether the node is a variable-arity container.
func (*ASTNode) IsStatement ¶ added in v0.12.0
IsStatement reports whether the node represents a statement.
func (*ASTNode) IsWrapper ¶ added in v0.8.0
IsWrapper reports whether the node is a syntactic wrapper (e.g. parens, argument list).
func (*ASTNode) LeafLabels ¶ added in v0.4.0
LeafLabels returns counts of each leaf label in the subtree.
func (*ASTNode) Leaves ¶ added in v0.4.0
Leaves returns all leaf nodes (and atomic string literals) in pre-order under n.
func (*ASTNode) LevelOrder ¶ added in v0.4.0
LevelOrder returns all nodes in the subtree level by level (breadth-first).
func (*ASTNode) SyntaxTrivia ¶ added in v0.12.0
func (n *ASTNode) SyntaxTrivia() *SyntaxTriviaBlock
SyntaxTrivia pulls this node's punctuation offsets from the index, returning nil if the node has no captured delimiters or the index isn't built.
type CommentBlock ¶ added in v0.12.0
type CommentBlock struct {
Type string
Text string
StartByte uint32
EndByte uint32
StartRow int // 0-indexed
StartCol int
EndRow int // 0-indexed
EndCol int
ScopeKey string
ParentType string
ParentStart uint32
ParentEnd uint32
ParentRow int
ParentEndRow int
Language string
IsComment bool
// Structural Declaration & Scope Context
DeclStart uint32
DeclEnd uint32
DeclType string
RelativePath string
EnclosingDecl *ASTNode
AnchorNode *ASTNode
}
CommentBlock represents an extracted comment and its source position.
type FlatASTResult ¶ added in v0.8.0
type FlatASTResult = C.FlatASTResult
type FlatNode ¶ added in v0.8.0
type FlatNode struct {
TypeID uint16
Flags uint16
StartByte uint32
EndByte uint32
StartRow uint32
StartCol uint32
EndRow uint32
EndCol uint32
ParentIdx uint32
FirstChildIdx uint32
NextSiblingIdx uint32
ChildCount uint32
}
FlatNode defines the 44-byte cache-aligned struct matching the C bridge layout.
type Language ¶ added in v0.8.0
type Language struct {
Name string
}
Language represents a recognized programming language.
func DetectLanguage ¶
DetectLanguage detects the language for a given filename or path.
type SyntaxTriviaBlock ¶ added in v0.12.0
type SyntaxTriviaBlock struct {
OpeningStart uint32
OpeningEnd uint32
ClosingStart uint32
ClosingEnd uint32
TrailingStart uint32
TrailingEnd uint32
}
SyntaxTriviaBlock holds CST punctuation byte spans (brackets, braces, separators) so diffing can absorb delimiters without adding synthetic nodes to the AST. All byte offsets are 0-indexed in the source file buffer.