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.
 
 

150 line
2.9 KiB

  1. # -*- coding: utf-8 -*-
  2. from types import ModuleType
  3. from typing import (
  4. TypeVar, Type, Tuple, List, Dict, Iterator, Collection, Callable, Optional,
  5. Pattern as REPattern,
  6. )
  7. from abc import abstractmethod, ABC
  8. _T = TypeVar('_T')
  9. class Pattern(ABC):
  10. value: str
  11. flags: Collection[str]
  12. def __init__(self, value: str, flags: Collection[str] = ...):
  13. ...
  14. @property
  15. @abstractmethod
  16. def type(self) -> str:
  17. ...
  18. @abstractmethod
  19. def to_regexp(self) -> str:
  20. ...
  21. @property
  22. @abstractmethod
  23. def min_width(self) -> int:
  24. ...
  25. @property
  26. @abstractmethod
  27. def max_width(self) -> int:
  28. ...
  29. class PatternStr(Pattern):
  30. type: str = ...
  31. def to_regexp(self) -> str:
  32. ...
  33. @property
  34. def min_width(self) -> int:
  35. ...
  36. @property
  37. def max_width(self) -> int:
  38. ...
  39. class PatternRE(Pattern):
  40. type: str = ...
  41. def to_regexp(self) -> str:
  42. ...
  43. @property
  44. def min_width(self) -> int:
  45. ...
  46. @property
  47. def max_width(self) -> int:
  48. ...
  49. class TerminalDef:
  50. name: str
  51. pattern: Pattern
  52. priority: int
  53. def __init__(self, name: str, pattern: Pattern, priority: int = ...):
  54. ...
  55. class Token(str):
  56. type: str
  57. pos_in_stream: int
  58. value: str
  59. line: int
  60. column: int
  61. end_line: int
  62. end_column: int
  63. end_pos: int
  64. def update(self, type_: Optional[str] = None, value: Optional[str] = None) -> Token:
  65. ...
  66. @classmethod
  67. def new_borrow_pos(cls: Type[_T], type_: str, value: str, borrow_t: Token) -> _T:
  68. ...
  69. _Callback = Callable[[Token], Token]
  70. class Lexer(ABC):
  71. lex: Callable[..., Iterator[Token]]
  72. class TraditionalLexer(Lexer):
  73. terminals: Collection[TerminalDef]
  74. ignore_types: List[str]
  75. newline_types: List[str]
  76. user_callbacks: Dict[str, _Callback]
  77. callback: Dict[str, _Callback]
  78. mres: List[Tuple[REPattern, Dict[int, str]]]
  79. re: ModuleType
  80. def __init__(
  81. self,
  82. terminals: Collection[TerminalDef],
  83. re_: ModuleType,
  84. ignore: Collection[str] = ...,
  85. user_callbacks: Dict[str, _Callback] = ...,
  86. g_regex_flags: int = ...
  87. ):
  88. ...
  89. def build(self) -> None:
  90. ...
  91. def match(self, stream: str, pos: int) -> Optional[Tuple[str, str]]:
  92. ...
  93. def lex(self, stream: str) -> Iterator[Token]:
  94. ...
  95. class ContextualLexer(Lexer):
  96. lexers: Dict[str, TraditionalLexer]
  97. root_lexer: TraditionalLexer
  98. def __init__(
  99. self,
  100. terminals: Collection[TerminalDef],
  101. states: Dict[str, Collection[str]],
  102. re_: ModuleType,
  103. ignore: Collection[str] = ...,
  104. always_accept: Collection[str] = ...,
  105. user_callbacks: Dict[str, _Callback] = ...,
  106. g_regex_flags: int = ...
  107. ):
  108. ...
  109. def lex(self, stream: str, get_parser_state: Callable[[], str]) -> Iterator[Token]:
  110. ...