/** * AST Parser 接口层 * * 提供统一的 AST 解析接口,支持 Rust 和 TypeScript 两种实现 */ import type { ParseResult } from '../types/codeEntity.js'; /** * AST 解析器接口 */ export interface ASTParser { /** * 解析文件内容 * @param filePath - 文件路径 * @param content - 文件内容 * @returns 解析结果 */ parseFile(filePath: string, content: string): Promise; /** * 批量解析文件(性能优化) * @param files - 文件列表 [filePath, content][] * @returns 解析结果数组 */ parseFilesInBatch(files: Array<[string, string]>): Promise; /** * 获取支持的文件扩展名 * @returns 扩展名列表 */ getSupportedExtensions(): string[]; } /** * Rust 实现的 AST 解析器(高性能) */ export declare class RustASTParser implements ASTParser { private parser; constructor(); parseFile(filePath: string, content: string): Promise; parseFilesInBatch(files: Array<[string, string]>): Promise; getSupportedExtensions(): string[]; /** * 检查 Rust 解析器是否可用 */ static isAvailable(): boolean; /** * 性能基准测试 * @param sourceCode - 源代码 * @param iterations - 迭代次数 * @returns 平均每次解析耗时(毫秒) */ static benchmark(sourceCode: string, iterations: number): Promise; } /** * TypeScript 实现的 AST 解析器(Fallback) * * 使用 ts-morph 实现,性能较低但无需编译 Rust */ export declare class TypeScriptASTParser implements ASTParser { parseFile(_filePath: string, _content: string): Promise; parseFilesInBatch(files: Array<[string, string]>): Promise; getSupportedExtensions(): string[]; } /** * 创建 AST 解析器(智能选择) * * @param preferRust - 优先使用 Rust 实现(默认 true) * @returns AST 解析器实例 */ export declare function createASTParser(preferRust?: boolean): ASTParser;