Expand description
§Document and Content Abstraction
Core traits for abstracting source code documents and their encoding across different platforms.
§Multi-Platform Support
thread-ast-engine supports multiple text encodings to work across different environments:
- UTF-8 - Standard for CLI applications and most Rust code
- UTF-16 - Required for Node.js NAPI bindings
Vec<char>- Used in WASM environments for JavaScript interop
Different encodings affect how byte positions and ranges are calculated in tree-sitter nodes, so this abstraction ensures consistent behavior across platforms.
§Key Concepts
§Documents (Doc)
Represents a complete source code document with its language and parsing information. Provides methods to access the source text, perform edits, and get AST nodes.
§Content (Content)
Abstracts the underlying text representation (bytes, UTF-16 code units, etc.). Handles encoding/decoding operations needed for text manipulation and replacement.
§Node Interface (SgNode)
Generic interface for AST nodes that works across different parser backends. Provides navigation, introspection, and traversal methods.
§Example Usage
// Documents abstract over different source encodings
let doc = StrDoc::new("const x = 42;", Language::JavaScript);
let root = doc.root_node();
// Content trait handles encoding differences transparently
let source_bytes = doc.get_source().get_range(0..5); // "const"Structs§
- Edit
- Represents an edit operation on source code.