From 8aebfbcabdc2feefd50b6813395aaddd491ce16b Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Mon, 2 Feb 2026 17:21:27 +0000 Subject: [PATCH] Add parsers module --- i18n_guardian/parsers/base.py | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 i18n_guardian/parsers/base.py diff --git a/i18n_guardian/parsers/base.py b/i18n_guardian/parsers/base.py new file mode 100644 index 0000000..6d11f44 --- /dev/null +++ b/i18n_guardian/parsers/base.py @@ -0,0 +1,51 @@ +"""Base parser interface.""" + +from abc import ABC, abstractmethod +from pathlib import Path +from typing import List, Optional + + +class StringLiteral: + """Represents a string literal found in code.""" + + def __init__( + self, + value: str, + file_path: Path, + line: int, + column: int, + end_line: Optional[int] = None, + end_column: Optional[int] = None, + is_template: bool = False, + ) -> None: + self.value = value + self.file_path = file_path + self.line = line + self.column = column + self.end_line = end_line + self.end_column = end_column + self.is_template = is_template + + def __repr__(self) -> str: + return f"StringLiteral({self.value!r}, {self.file_path}:{self.line})" + + +class Parser(ABC): + """Base class for code parsers.""" + + @property + @abstractmethod + def name(self) -> str: + """Parser name.""" + pass + + @property + @abstractmethod + def extensions(self) -> List[str]: + """File extensions this parser handles.""" + pass + + @abstractmethod + def parse(self, file_path: Path) -> List[StringLiteral]: + """Parse a file and extract string literals.""" + pass