This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
974 B

  1. # -*- coding: utf-8 -*-
  2. from typing import Tuple, Iterator, Sized
  3. from abc import abstractmethod, ABC
  4. class Pattern(ABC):
  5. @abstractmethod
  6. def to_regexp(self) -> str:
  7. ...
  8. class PatternStr(Pattern):
  9. def to_regexp(self) -> str:
  10. ...
  11. class PatternRE(Pattern):
  12. def to_regexp(self) -> str:
  13. ...
  14. class TerminalDef:
  15. name: str
  16. pattern: Pattern
  17. priority: int
  18. class Token(str):
  19. type: str
  20. pos_in_stream: int
  21. line: int
  22. column: int
  23. end_line: int
  24. end_column: int
  25. end_pos: int
  26. class Lexer(ABC):
  27. @abstractmethod
  28. def lex(self, stream: Sized) -> Iterator[Token]:
  29. ...
  30. class TraditionalLexer(Lexer):
  31. def build(self) -> None:
  32. ...
  33. def match(self, stream: str, pos: int) -> Tuple[str, str]:
  34. ...
  35. def lex(self, stream: Sized) -> Iterator[Token]:
  36. ...
  37. class ContextualLexer(Lexer):
  38. def lex(self, stream: Sized) -> Iterator[Token]:
  39. ...