This commit is contained in:
Mikan
2025-06-02 14:16:03 +03:00
commit 83cfcd9fb1
19 changed files with 430 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
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") 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