/** * Tree-sitter Parser * * Uses web-tree-sitter (WebAssembly) for parsing multiple languages. * This parser supports Python, Go, Rust, Java, and can act as a fallback for TS/JS. * * Web-tree-sitter provides: * - Cross-platform compatibility (no native compilation) * - Fast, incremental parsing * - Support for many languages via WASM grammars * - Consistent AST structure */ import type { IParser, ParseResult, ParserConfig, ParserLanguage } from "../../domain/ports/parser"; /** * Tree-sitter Parser implementation using web-tree-sitter (WebAssembly). * * Supports multiple languages through WASM grammar files. * Falls back to basic chunking if grammar is not available. */ export declare class TreeSitterParser implements IParser { readonly supportedLanguages: ParserLanguage[]; private grammarManager; private parserInstance; private loadedLanguages; private initPromise; /** * Parse source code into semantic chunks using tree-sitter. */ parse(content: string, filepath: string, config?: ParserConfig): Promise; /** * Check if this parser can handle the given file. */ canParse(filepath: string): boolean; /** * Detect language from file extension. */ private detectLanguage; /** * Ensure tree-sitter is initialized. */ private ensureInitialized; /** * Initialize web-tree-sitter. */ private initializeTreeSitter; /** * Resolve the path to the web-tree-sitter.wasm file. * Tries multiple strategies to find the file. */ private resolveWasmPath; /** * Load a language module for tree-sitter. * Returns null if the language is not available. */ private loadLanguage; /** * Parse source code with tree-sitter. */ private parseWithTreeSitter; /** * Extract chunks from Python AST. */ private extractPythonChunks; /** * Extract chunks from Go AST. */ private extractGoChunks; /** * Extract chunks from Rust AST. */ private extractRustChunks; /** * Extract chunks from Java AST. */ private extractJavaChunks; /** * Extract generic chunks. */ private extractGenericChunks; /** * Create a chunk from a tree-sitter node. */ private createChunkFromNode; /** * Get the text content of a tree-sitter node. */ private getNodeText; /** * Find a preceding comment (for Go-style comments). */ private findPrecedingComment; /** * Find Rust doc comments (/// or //!). */ private findRustDocComment; /** * Find Javadoc comments. */ private findJavadoc; /** * Fall back to basic line-based parsing. */ private fallbackParse; } /** * Create a new tree-sitter parser instance. */ export declare function createTreeSitterParser(): TreeSitterParser;