diff --git a/codemap/parsers/base.py b/codemap/parsers/base.py new file mode 100644 index 0000000..37c4fbe --- /dev/null +++ b/codemap/parsers/base.py @@ -0,0 +1,39 @@ +from abc import ABC, abstractmethod +from dataclasses import dataclass +from pathlib import Path +from typing import List, Set + + +@dataclass +class Dependency: + module_name: str + file_path: Path + line_number: int + alias: str = None + + +@dataclass +class ParsedFile: + file_path: Path + module_name: str + dependencies: List[Dependency] + file_type: str + + +class BaseParser(ABC): + supported_extensions: List[str] = [] + + @abstractmethod + def parse(self, file_path: Path) -> ParsedFile: + pass + + @abstractmethod + def extract_module_name(self, file_path: Path) -> str: + pass + + def can_parse(self, file_path: Path) -> bool: + return file_path.suffix in self.supported_extensions + + def _clean_import_name(self, import_str: str) -> str: + parts = import_str.split(".") + return parts[0]