Files
G4F/ReactDev/core/file_analyzer.py
2025-06-02 14:22:46 +03:00

37 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import esprima
from ..utils.logger import log
class FileAnalyzer:
def __init__(self):
pass
def analyze_file(self, file_path: str) -> dict:
"""
Анализирует файл и извлекает информацию о функциях.
"""
log(f"Analyzing file: {file_path}")
with open(file_path, "r", encoding="utf-8") as f:
code = f.read()
try:
parsed = esprima.parseScript(code, loc=True)
functions = self._extract_functions(parsed)
return functions
except Exception as e:
log(f"Error parsing file {file_path}: {e}", level="error")
return {}
def _extract_functions(self, ast: dict) -> dict:
"""
Извлекает информацию о функциях из AST.
"""
functions = {}
for node in ast.body:
if node.type == "FunctionDeclaration":
name = node.id.name
params = [param.name for param in node.params]
functions[name] = {
"params": params,
"return_type": "unknown", # Тип возвращаемого значения не всегда доступен
}
return functions