Expand description
§Tree-sitter Integration and AST Backend
Core integration layer between thread-ast-engine and the tree-sitter parsing library. Provides the foundational types and functionality for parsing source code into ASTs, editing trees incrementally, and bridging tree-sitter concepts with thread-ast-engine APIs.
§Key Components
StrDoc- Document type that combines source code with parsed tree-sitter treesLanguageExt- Extension trait for languages that work with tree-sitterTSParseError- Error types for tree-sitter parsing failures- Tree editing and incremental parsing support
- Language injection support for multi-language documents
§Core Concepts
§Documents and Parsing
StrDoc represents a parsed document containing both source code and its tree-sitter AST.
It handles incremental parsing when the source is modified, automatically updating the tree
structure while preserving unchanged portions for performance.
§Language Extensions
LanguageExt extends the base Language trait with tree-sitter specific functionality:
- Getting tree-sitter language objects for parsing
- Creating AST-grep instances
- Handling language injections (like JavaScript in HTML)
§Tree Editing
Supports incremental tree editing through tree-sitter’s edit API, allowing efficient updates when source code changes without full re-parsing.
§Example Usage
// Create a document from source code
let doc = StrDoc::new("let x = 42;", Tsx);
// Access the parsed tree
let root = doc.root_node();
println!("Root kind: {}", root.kind());
// Create an AST-grep instance for pattern matching
let ast_grep = Tsx.ast_grep("function foo() { return 42; }");
let root_node = ast_grep.root();Re-exports§
Modules§
- traversal
- AST Tree Traversal Algorithms
Structs§
- Display
Context - StrDoc
- Document type that combines source code with its parsed tree-sitter AST.
- TSLanguage
- An opaque object that defines how to parse a particular language. The code
for each
Languageis generated by the Tree-sitter CLI. - TSPoint
- A position in a multi-line text document, in terms of rows and columns.
- TSRange
- A range of positions in a multi-line text document, both in terms of bytes and of rows and columns.
Enums§
- TSParse
Error - Errors that can occur during tree-sitter parsing operations.
Traits§
- Content
Ext - Language
Ext - Extension trait for languages that integrate with tree-sitter parsing.