/** * Tree-sitter Parser Module * * Provides AST parsing capabilities using web-tree-sitter (WASM-based) * for cross-platform compatibility. Supports multiple programming languages * with lazy loading of language grammars. * * @module treeSitterParser */ import * as TreeSitter from 'web-tree-sitter'; export type { Tree, Node, Language, TreeCursor, Query, QueryMatch, QueryCapture } from 'web-tree-sitter'; /** * Supported programming languages for AST-based chunking */ export type ASTLanguage = 'javascript' | 'typescript' | 'tsx' | 'python' | 'go' | 'java' | 'rust' | 'c' | 'cpp' | 'csharp'; /** * Tree-sitter parser wrapper with lazy loading and caching * * Features: * - WASM-based parsing (cross-platform) * - Lazy loading of language grammars * - Language caching for performance * - Graceful error handling * * @example * ```typescript * const parser = TreeSitterParserWrapper.getInstance(); * await parser.initialize(); * const tree = await parser.parse(sourceCode, 'file.ts'); * ``` */ export declare class TreeSitterParser { private static instance; private parser; private languageCache; private initialized; private initializing; private wasmBasePath; private constructor(); /** * Get the singleton instance of TreeSitterParser */ static getInstance(): TreeSitterParser; /** * Initialize the parser (must be called before parsing) * * This method is idempotent - calling it multiple times is safe. */ initialize(): Promise; /** * Find the web-tree-sitter WASM file path */ private findWasmPath; /** * Find the tree-sitter-wasms base path */ private findWasmBasePath; /** * Load a language grammar * * @param language - Language to load * @returns Language grammar or null if not available */ private loadLanguage; /** * Parse source code and return the AST * * @param sourceCode - Source code to parse * @param filePath - File path (used for language detection) * @returns Parsed tree or null if parsing failed */ parse(sourceCode: string, filePath: string): Promise; /** * Check if a file type is supported for AST parsing * * @param filePath - File path to check * @returns true if the file type is supported */ isSupported(filePath: string): boolean; /** * Get the language for a file path * * @param filePath - File path to check * @returns Language name or null if not supported */ getLanguage(filePath: string): ASTLanguage | null; /** * Get all supported file extensions * * @returns Array of supported file extensions */ getSupportedExtensions(): string[]; /** * Get all supported languages * * @returns Array of supported language names */ getSupportedLanguages(): ASTLanguage[]; /** * Check if the parser is initialized */ get isInitialized(): boolean; /** * Clean up resources */ cleanup(): void; } /** * Get the Tree-sitter parser instance * * @returns TreeSitterParser singleton instance */ export declare function getTreeSitterParser(): TreeSitterParser; /** * Check if AST-based chunking is supported for a file * * @param filePath - File path to check * @returns true if AST chunking is supported */ export declare function supportsASTChunking(filePath: string): boolean; /** * Get the AST language for a file path * * @param filePath - File path to check * @returns Language name or null if not supported */ export declare function getASTLanguage(filePath: string): ASTLanguage | null; //# sourceMappingURL=treeSitterParser.d.ts.map