This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

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