/** * SMI-1304: Python Language Adapter * * Parses Python source files (.py, .pyi, .pyw) and extracts * imports, exports, and function definitions using regex-based * parsing with optional tree-sitter support for incremental parsing. * * @see docs/internal/architecture/multi-language-analysis.md */ import { LanguageAdapter, type SupportedLanguage, type FrameworkRule } from './base.js'; import type { ParseResult } from '../types.js'; /** * Python adapter using regex-based parsing with optional tree-sitter * * The adapter provides: * - Synchronous regex-based parsing for basic analysis * - Async tree-sitter parsing for enhanced accuracy (when available) * - Framework detection rules for Django, FastAPI, Flask, etc. * * @example * ```typescript * const adapter = new PythonAdapter() * * const result = adapter.parseFile(` * import os * from django.http import HttpResponse * * def hello(request): * return HttpResponse("Hello") * `, 'views.py') * * console.log(result.imports) // [{ module: 'os', ... }, { module: 'django.http', ... }] * console.log(result.functions) // [{ name: 'hello', ... }] * ``` */ export declare class PythonAdapter extends LanguageAdapter { readonly language: SupportedLanguage; readonly extensions: string[]; private incremental; private initPromise; /** * Initialize the tree-sitter parser (lazy loaded) * * Instantiates the WASM-backed PythonIncrementalParser so subsequent * incremental / query-based calls can run synchronously. */ initParser(): Promise; /** * Parse a Python file using regex-based parsing * * @param content - Python source code * @param filePath - Path to the file (for source tracking) * @returns Parsed imports, exports, and functions */ parseFile(content: string, filePath: string): ParseResult; /** * Parse a Python file asynchronously with tree-sitter (if available) * * Falls back to regex parsing if tree-sitter is not available. * * @param content - Python source code * @param filePath - Path to the file (for source tracking) * @returns Promise resolving to parsed imports, exports, and functions */ parseFileAsync(content: string, filePath: string): Promise; /** * Parse file incrementally using a previously cached parse tree. * * When the WASM parser has been initialised (via `parseFileAsync` or * `initParser`), this path reuses the cached tree with `tree.edit()` and * re-parses only the changed region, delegating extraction to * tree-sitter queries. On any failure it gracefully falls back to the * regex baseline. * * @param content - Updated Python source code * @param filePath - Path to the file * @param _previousTree - Reserved for external callers that want to pass * a tree explicitly; the adapter manages its own cache and ignores it. * @returns Parsed imports, exports, and functions */ parseIncremental(content: string, filePath: string, _previousTree?: unknown): ParseResult; /** * Get Python framework detection rules * * @returns Array of framework detection rules */ getFrameworkRules(): FrameworkRule[]; /** * Clean up resources */ dispose(): void; /** * Parse Python source code using regex patterns */ private parseWithRegex; /** * Extract imports from Python source code */ private extractImports; /** * Parse comma-separated import names, handling aliases */ private parseImportNames; /** * Extract exports from Python source code */ private extractExports; /** * Extract function definitions from Python source code */ private extractFunctions; /** * Parse Python source code using tree-sitter for more accurate results. * * Delegates to the query-based extractor when the WASM parser is ready; * falls back to regex otherwise so the adapter always returns a result. */ private parseWithTreeSitter; } //# sourceMappingURL=python.d.ts.map