This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

166 Zeilen
3.4 KiB

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