Format: application/octet-stream
1 import sys
2 from lib2to3.pgen2.grammar import Grammar
3 from typing import Any, Callable, Dict, Iterator, List, Optional, Text, Tuple, TypeVar, Union
4
5 _P = TypeVar("_P")
6 _NL = Union[Node, Leaf]
7 _Context = Tuple[Text, int, int]
8 _Results = Dict[Text, _NL]
9 _RawNode = Tuple[int, Text, _Context, Optional[List[_NL]]]
10 _Convert = Callable[[Grammar, _RawNode], Any]
11
12 HUGE: int
13
14 def type_repr(type_num: int) -> Text: ...
15
16 class Base:
17 type: int
18 parent: Optional[Node]
19 prefix: Text
20 children: List[_NL]
21 was_changed: bool
22 was_checked: bool
23 def __eq__(self, other: Any) -> bool: ...
24 def _eq(self: _P, other: _P) -> bool: ...
25 def clone(self: _P) -> _P: ...
26 def post_order(self) -> Iterator[_NL]: ...
27 def pre_order(self) -> Iterator[_NL]: ...
28 def replace(self, new: Union[_NL, List[_NL]]) -> None: ...
29 def get_lineno(self) -> int: ...
30 def changed(self) -> None: ...
31 def remove(self) -> Optional[int]: ...
32 @property
33 def next_sibling(self) -> Optional[_NL]: ...
34 @property
35 def prev_sibling(self) -> Optional[_NL]: ...
36 def leaves(self) -> Iterator[Leaf]: ...
37 def depth(self) -> int: ...
38 def get_suffix(self) -> Text: ...
39 if sys.version_info < (3,):
40 def get_prefix(self) -> Text: ...
41 def set_prefix(self, prefix: Text) -> None: ...
42
43 class Node(Base):
44 fixers_applied: List[Any]
45 def __init__(
46 self,
47 type: int,
48 children: List[_NL],
49 context: Optional[Any] = ...,
50 prefix: Optional[Text] = ...,
51 fixers_applied: Optional[List[Any]] = ...,
52 ) -> None: ...
53 def set_child(self, i: int, child: _NL) -> None: ...
54 def insert_child(self, i: int, child: _NL) -> None: ...
55 def append_child(self, child: _NL) -> None: ...
56
57 class Leaf(Base):
58 lineno: int
59 column: int
60 value: Text
61 fixers_applied: List[Any]
62 def __init__(
63 self,
64 type: int,
65 value: Text,
66 context: Optional[_Context] = ...,
67 prefix: Optional[Text] = ...,
68 fixers_applied: List[Any] = ...,
69 ) -> None: ...
70
71 def convert(gr: Grammar, raw_node: _RawNode) -> _NL: ...
72
73 class BasePattern:
74 type: int
75 content: Optional[Text]
76 name: Optional[Text]
77 def optimize(self) -> BasePattern: ... # sic, subclasses are free to optimize themselves into different patterns
78 def match(self, node: _NL, results: Optional[_Results] = ...) -> bool: ...
79 def match_seq(self, nodes: List[_NL], results: Optional[_Results] = ...) -> bool: ...
80 def generate_matches(self, nodes: List[_NL]) -> Iterator[Tuple[int, _Results]]: ...
81
82 class LeafPattern(BasePattern):
83 def __init__(self, type: Optional[int] = ..., content: Optional[Text] = ..., name: Optional[Text] = ...) -> None: ...
84
85 class NodePattern(BasePattern):
86 wildcards: bool
87 def __init__(self, type: Optional[int] = ..., content: Optional[Text] = ..., name: Optional[Text] = ...) -> None: ...
88
89 class WildcardPattern(BasePattern):
90 min: int
91 max: int
92 def __init__(self, content: Optional[Text] = ..., min: int = ..., max: int = ..., name: Optional[Text] = ...) -> None: ...
93
94 class NegatedPattern(BasePattern):
95 def __init__(self, content: Optional[Text] = ...) -> None: ...
96
97 def generate_matches(patterns: List[BasePattern], nodes: List[_NL]) -> Iterator[Tuple[int, _Results]]: ...
98