import { getCurrentParsingFile, log, logCore, ParserExtraMensagens, wrapMinimal } from '../utils.js';
export function parseComPython(codigo) {
    try {
        const classes = Array.from(codigo.matchAll(/^\s*class\s+([A-Za-z0-9_]+)/gm)).map(m => m[1]);
        const functions = Array.from(codigo.matchAll(/^\s*def\s+([A-Za-z0-9_]+)/gm)).map(m => m[1]);
        const asyncFunctions = Array.from(codigo.matchAll(/^\s*async\s+def\s+([A-Za-z0-9_]+)/gm)).map(m => m[1]);
        const imports = Array.from(codigo.matchAll(/^\s*(?:from\s+([\w.]+)\s+)?import\s+(.+)$/gm)).map(m => ({
            module: m[1] || null,
            names: m[2]?.split(',').map(s => s.trim().split(/\s+as\s+/)[0]).filter(Boolean) || []
        }));
        const decorators = Array.from(codigo.matchAll(/^\s*@([A-Za-z0-9_.]+)/gm)).map(m => m[1]);
        const topLevelVars = Array.from(codigo.matchAll(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=(?!=)/gm)).map(m => m[1]);
        const constants = Array.from(codigo.matchAll(/^\s*([A-Z][A-Z0-9_]+)\s*=/gm)).map(m => m[1]);
        const dunderMethods = Array.from(codigo.matchAll(/^\s*def\s+(__[a-z]+__)\s*\(/gm)).map(m => m[1]);
        const classInheritance = Array.from(codigo.matchAll(/^\s*class\s+([A-Za-z0-9_]+)\s*\(([^)]*)\)/gm)).map(m => ({
            class: m[1],
            bases: m[2].split(',').map(b => b.trim()).filter(Boolean)
        }));
        log.debug(ParserExtraMensagens.pythonParse
            .replace('{classes}', String(classes.length))
            .replace('{functions}', String(functions.length))
            .replace('{asyncFunctions}', String(asyncFunctions.length)));
        return wrapMinimal('python', {
            classes,
            functions,
            asyncFunctions,
            imports,
            decorators,
            topLevelVars,
            constants,
            dunderMethods,
            classInheritance,
            totalImports: imports.reduce((acc, i) => acc + i.names.length, 0)
        });
    }
    catch (erro) {
        logCore.erroBabel(erro.message, getCurrentParsingFile());
        return null;
    }
}
//# sourceMappingURL=python.js.map