Files
7000pctAUTO 8aebfbcabd
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
Add parsers module
2026-02-02 17:21:27 +00:00

52 lines
1.2 KiB
Python

"""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