id
int64
1
6.07M
name
stringlengths
1
295
code
stringlengths
12
426k
language
stringclasses
1 value
source_file
stringlengths
5
202
start_line
int64
1
158k
end_line
int64
1
158k
repo
dict
10,201
name
def name(self, node: Rule) -> str: if not list(self.children(node)): return repr(node) return node.__class__.__name__
python
Tools/peg_generator/pegen/grammar_visualizer.py
22
25
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,202
print_grammar_ast
def print_grammar_ast(self, grammar: Grammar, printer: Callable[..., None] = print) -> None: for rule in grammar.rules.values(): printer(self.print_nodes_recursively(rule))
python
Tools/peg_generator/pegen/grammar_visualizer.py
27
29
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,203
print_nodes_recursively
def print_nodes_recursively(self, node: Rule, prefix: str = "", istail: bool = True) -> str: children = list(self.children(node)) value = self.name(node) line = prefix + ("└──" if istail else "├──") + value + "\n" sufix = " " if istail else "│ " if not children: ...
python
Tools/peg_generator/pegen/grammar_visualizer.py
31
46
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,204
main
def main() -> None: args = argparser.parse_args() try: grammar, parser, tokenizer = build_parser(args.filename) except Exception as err: print("ERROR: Failed to parse grammar file", file=sys.stderr) sys.exit(1) visitor = ASTGrammarPrinter() visitor.print_grammar_ast(grammar...
python
Tools/peg_generator/pegen/grammar_visualizer.py
49
59
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,205
visit
def visit(self, node: Any, *args: Any, **kwargs: Any) -> Any: """Visit a node.""" method = "visit_" + node.__class__.__name__ visitor = getattr(self, method, self.generic_visit) return visitor(node, *args, **kwargs)
python
Tools/peg_generator/pegen/grammar.py
20
24
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,206
generic_visit
def generic_visit(self, node: Iterable[Any], *args: Any, **kwargs: Any) -> Any: """Called if no explicit visitor function exists for a node.""" for value in node: if isinstance(value, list): for item in value: self.visit(item, *args, **kwargs) ...
python
Tools/peg_generator/pegen/grammar.py
26
33
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,207
__init__
def __init__(self, rules: Iterable[Rule], metas: Iterable[Tuple[str, Optional[str]]]): # Check if there are repeated rules in "rules" all_rules = {} for rule in rules: if rule.name in all_rules: raise GrammarError(f"Repeated rule {rule.name!r}") all_rules[...
python
Tools/peg_generator/pegen/grammar.py
37
45
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,208
__str__
def __str__(self) -> str: return "\n".join(str(rule) for name, rule in self.rules.items())
python
Tools/peg_generator/pegen/grammar.py
47
48
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,209
__repr__
def __repr__(self) -> str: lines = ["Grammar("] lines.append(" [") for rule in self.rules.values(): lines.append(f" {repr(rule)},") lines.append(" ],") lines.append(" {repr(list(self.metas.items()))}") lines.append(")") return "\n".join(lines)
python
Tools/peg_generator/pegen/grammar.py
50
58
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,210
__iter__
def __iter__(self) -> Iterator[Rule]: yield from self.rules.values()
python
Tools/peg_generator/pegen/grammar.py
60
61
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,211
__init__
def __init__(self, name: str, type: Optional[str], rhs: Rhs, memo: Optional[object] = None): self.name = name self.type = type self.rhs = rhs self.memo = bool(memo) self.left_recursive = False self.leader = False
python
Tools/peg_generator/pegen/grammar.py
69
75
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,212
is_loop
def is_loop(self) -> bool: return self.name.startswith("_loop")
python
Tools/peg_generator/pegen/grammar.py
77
78
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,213
is_gather
def is_gather(self) -> bool: return self.name.startswith("_gather")
python
Tools/peg_generator/pegen/grammar.py
80
81
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,214
__str__
def __str__(self) -> str: if SIMPLE_STR or self.type is None: res = f"{self.name}: {self.rhs}" else: res = f"{self.name}[{self.type}]: {self.rhs}" if len(res) < 88: return res lines = [res.split(":")[0] + ":"] lines += [f" | {alt}" for alt i...
python
Tools/peg_generator/pegen/grammar.py
83
92
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,215
__repr__
def __repr__(self) -> str: return f"Rule({self.name!r}, {self.type!r}, {self.rhs!r})"
python
Tools/peg_generator/pegen/grammar.py
94
95
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,216
__iter__
def __iter__(self) -> Iterator[Rhs]: yield self.rhs
python
Tools/peg_generator/pegen/grammar.py
97
98
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,217
flatten
def flatten(self) -> Rhs: # If it's a single parenthesized group, flatten it. rhs = self.rhs if ( not self.is_loop() and len(rhs.alts) == 1 and len(rhs.alts[0].items) == 1 and isinstance(rhs.alts[0].items[0].item, Group) ): rhs ...
python
Tools/peg_generator/pegen/grammar.py
100
110
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,218
__init__
def __init__(self, value: str): self.value = value
python
Tools/peg_generator/pegen/grammar.py
114
115
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,219
__str__
def __str__(self) -> str: return self.value
python
Tools/peg_generator/pegen/grammar.py
117
118
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,220
__iter__
def __iter__(self) -> Iterable[str]: yield from ()
python
Tools/peg_generator/pegen/grammar.py
120
121
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,221
__str__
def __str__(self) -> str: if self.value == "ENDMARKER": return "$" return super().__str__()
python
Tools/peg_generator/pegen/grammar.py
127
130
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,222
__repr__
def __repr__(self) -> str: return f"NameLeaf({self.value!r})"
python
Tools/peg_generator/pegen/grammar.py
132
133
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,223
__repr__
def __repr__(self) -> str: return f"StringLeaf({self.value!r})"
python
Tools/peg_generator/pegen/grammar.py
139
140
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,224
__init__
def __init__(self, alts: List[Alt]): self.alts = alts self.memo: Optional[Tuple[Optional[str], str]] = None
python
Tools/peg_generator/pegen/grammar.py
144
146
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,225
__str__
def __str__(self) -> str: return " | ".join(str(alt) for alt in self.alts)
python
Tools/peg_generator/pegen/grammar.py
148
149
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,226
__repr__
def __repr__(self) -> str: return f"Rhs({self.alts!r})"
python
Tools/peg_generator/pegen/grammar.py
151
152
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,227
__iter__
def __iter__(self) -> Iterator[List[Alt]]: yield self.alts
python
Tools/peg_generator/pegen/grammar.py
154
155
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,228
can_be_inlined
def can_be_inlined(self) -> bool: if len(self.alts) != 1 or len(self.alts[0].items) != 1: return False # If the alternative has an action we cannot inline if getattr(self.alts[0], "action", None) is not None: return False return True
python
Tools/peg_generator/pegen/grammar.py
158
164
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,229
__init__
def __init__(self, items: List[NamedItem], *, icut: int = -1, action: Optional[str] = None): self.items = items self.icut = icut self.action = action
python
Tools/peg_generator/pegen/grammar.py
168
171
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,230
__str__
def __str__(self) -> str: core = " ".join(str(item) for item in self.items) if not SIMPLE_STR and self.action: return f"{core} {{ {self.action} }}" else: return core
python
Tools/peg_generator/pegen/grammar.py
173
178
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,231
__repr__
def __repr__(self) -> str: args = [repr(self.items)] if self.icut >= 0: args.append(f"icut={self.icut}") if self.action: args.append(f"action={self.action!r}") return f"Alt({', '.join(args)})"
python
Tools/peg_generator/pegen/grammar.py
180
186
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,232
__iter__
def __iter__(self) -> Iterator[List[NamedItem]]: yield self.items
python
Tools/peg_generator/pegen/grammar.py
188
189
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,233
__init__
def __init__(self, name: Optional[str], item: Item, type: Optional[str] = None): self.name = name self.item = item self.type = type
python
Tools/peg_generator/pegen/grammar.py
193
196
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,234
__str__
def __str__(self) -> str: if not SIMPLE_STR and self.name: return f"{self.name}={self.item}" else: return str(self.item)
python
Tools/peg_generator/pegen/grammar.py
198
202
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,235
__repr__
def __repr__(self) -> str: return f"NamedItem({self.name!r}, {self.item!r})"
python
Tools/peg_generator/pegen/grammar.py
204
205
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,236
__iter__
def __iter__(self) -> Iterator[Item]: yield self.item
python
Tools/peg_generator/pegen/grammar.py
207
208
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,237
__init__
def __init__(self, node: Plain): self.node = node
python
Tools/peg_generator/pegen/grammar.py
212
213
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,238
__str__
def __str__(self) -> str: return f"&&{self.node}"
python
Tools/peg_generator/pegen/grammar.py
215
216
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,239
__iter__
def __iter__(self) -> Iterator[Plain]: yield self.node
python
Tools/peg_generator/pegen/grammar.py
218
219
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,240
__init__
def __init__(self, node: Plain, sign: str): self.node = node self.sign = sign
python
Tools/peg_generator/pegen/grammar.py
223
225
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,241
__str__
def __str__(self) -> str: return f"{self.sign}{self.node}"
python
Tools/peg_generator/pegen/grammar.py
227
228
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,242
__iter__
def __iter__(self) -> Iterator[Plain]: yield self.node
python
Tools/peg_generator/pegen/grammar.py
230
231
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,243
__init__
def __init__(self, node: Plain): super().__init__(node, "&")
python
Tools/peg_generator/pegen/grammar.py
235
236
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,244
__repr__
def __repr__(self) -> str: return f"PositiveLookahead({self.node!r})"
python
Tools/peg_generator/pegen/grammar.py
238
239
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,245
__init__
def __init__(self, node: Plain): super().__init__(node, "!")
python
Tools/peg_generator/pegen/grammar.py
243
244
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,246
__repr__
def __repr__(self) -> str: return f"NegativeLookahead({self.node!r})"
python
Tools/peg_generator/pegen/grammar.py
246
247
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,247
__init__
def __init__(self, node: Item): self.node = node
python
Tools/peg_generator/pegen/grammar.py
251
252
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,248
__str__
def __str__(self) -> str: s = str(self.node) # TODO: Decide whether to use [X] or X? based on type of X if " " in s: return f"[{s}]" else: return f"{s}?"
python
Tools/peg_generator/pegen/grammar.py
254
260
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,249
__repr__
def __repr__(self) -> str: return f"Opt({self.node!r})"
python
Tools/peg_generator/pegen/grammar.py
262
263
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,250
__iter__
def __iter__(self) -> Iterator[Item]: yield self.node
python
Tools/peg_generator/pegen/grammar.py
265
266
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,251
__init__
def __init__(self, node: Plain): self.node = node self.memo: Optional[Tuple[Optional[str], str]] = None
python
Tools/peg_generator/pegen/grammar.py
272
274
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,252
__iter__
def __iter__(self) -> Iterator[Plain]: yield self.node
python
Tools/peg_generator/pegen/grammar.py
276
277
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,253
__str__
def __str__(self) -> str: s = str(self.node) # TODO: Decide whether to use (X)* or X* based on type of X if " " in s: return f"({s})*" else: return f"{s}*"
python
Tools/peg_generator/pegen/grammar.py
281
287
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,254
__repr__
def __repr__(self) -> str: return f"Repeat0({self.node!r})"
python
Tools/peg_generator/pegen/grammar.py
289
290
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,255
__str__
def __str__(self) -> str: s = str(self.node) # TODO: Decide whether to use (X)+ or X+ based on type of X if " " in s: return f"({s})+" else: return f"{s}+"
python
Tools/peg_generator/pegen/grammar.py
294
300
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,256
__repr__
def __repr__(self) -> str: return f"Repeat1({self.node!r})"
python
Tools/peg_generator/pegen/grammar.py
302
303
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,257
__init__
def __init__(self, separator: Plain, node: Plain): self.separator = separator self.node = node
python
Tools/peg_generator/pegen/grammar.py
307
309
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,258
__str__
def __str__(self) -> str: return f"{self.separator!s}.{self.node!s}+"
python
Tools/peg_generator/pegen/grammar.py
311
312
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,259
__repr__
def __repr__(self) -> str: return f"Gather({self.separator!r}, {self.node!r})"
python
Tools/peg_generator/pegen/grammar.py
314
315
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,260
__init__
def __init__(self, rhs: Rhs): self.rhs = rhs
python
Tools/peg_generator/pegen/grammar.py
319
320
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,261
__str__
def __str__(self) -> str: return f"({self.rhs})"
python
Tools/peg_generator/pegen/grammar.py
322
323
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,262
__repr__
def __repr__(self) -> str: return f"Group({self.rhs!r})"
python
Tools/peg_generator/pegen/grammar.py
325
326
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,263
__iter__
def __iter__(self) -> Iterator[Rhs]: yield self.rhs
python
Tools/peg_generator/pegen/grammar.py
328
329
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,264
__init__
def __init__(self) -> None: pass
python
Tools/peg_generator/pegen/grammar.py
333
334
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,265
__repr__
def __repr__(self) -> str: return f"Cut()"
python
Tools/peg_generator/pegen/grammar.py
336
337
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,266
__str__
def __str__(self) -> str: return f"~"
python
Tools/peg_generator/pegen/grammar.py
339
340
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,267
__iter__
def __iter__(self) -> Iterator[Tuple[str, str]]: yield from ()
python
Tools/peg_generator/pegen/grammar.py
342
343
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,268
__eq__
def __eq__(self, other: object) -> bool: if not isinstance(other, Cut): return NotImplemented return True
python
Tools/peg_generator/pegen/grammar.py
345
348
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,269
initial_names
def initial_names(self) -> AbstractSet[str]: return set()
python
Tools/peg_generator/pegen/grammar.py
350
351
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,270
logger
def logger(method: F) -> F: """For non-memoized functions that we want to be logged. (In practice this is only non-leader left-recursive functions.) """ method_name = method.__name__ def logger_wrapper(self: "Parser", *args: object) -> Any: if not self._verbose: return method(s...
python
Tools/peg_generator/pegen/parser.py
16
36
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,271
logger_wrapper
def logger_wrapper(self: "Parser", *args: object) -> Any: if not self._verbose: return method(self, *args) argsr = ",".join(repr(arg) for arg in args) fill = " " * self._level print(f"{fill}{method_name}({argsr}) .... (looking at {self.showpeek()})") self._level += 1...
python
Tools/peg_generator/pegen/parser.py
23
33
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,272
memoize
def memoize(method: F) -> F: """Memoize a symbol method.""" method_name = method.__name__ def memoize_wrapper(self: "Parser", *args: object) -> Any: mark = self._mark() key = mark, method_name, args # Fast path: cache hit, and not verbose. if key in self._cache and not self....
python
Tools/peg_generator/pegen/parser.py
39
73
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,273
memoize_wrapper
def memoize_wrapper(self: "Parser", *args: object) -> Any: mark = self._mark() key = mark, method_name, args # Fast path: cache hit, and not verbose. if key in self._cache and not self._verbose: tree, endmark = self._cache[key] self._reset(endmark) ret...
python
Tools/peg_generator/pegen/parser.py
43
70
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,274
memoize_left_rec
def memoize_left_rec( method: Callable[["Parser"], Optional[T]] ) -> Callable[["Parser"], Optional[T]]: """Memoize a left-recursive symbol method.""" method_name = method.__name__ def memoize_left_rec_wrapper(self: "Parser") -> Optional[T]: mark = self._mark() key = mark, method_name, (...
python
Tools/peg_generator/pegen/parser.py
76
157
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,275
memoize_left_rec_wrapper
def memoize_left_rec_wrapper(self: "Parser") -> Optional[T]: mark = self._mark() key = mark, method_name, () # Fast path: cache hit, and not verbose. if key in self._cache and not self._verbose: tree, endmark = self._cache[key] self._reset(endmark) ret...
python
Tools/peg_generator/pegen/parser.py
82
154
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,276
__init__
def __init__(self, tokenizer: Tokenizer, *, verbose: bool = False): self._tokenizer = tokenizer self._verbose = verbose self._level = 0 self._cache: Dict[Tuple[Mark, str, Tuple[Any, ...]], Tuple[Any, Mark]] = {} # Integer tracking whether we are in a left recursive rule or not. C...
python
Tools/peg_generator/pegen/parser.py
167
177
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,277
start
def start(self) -> Any: pass
python
Tools/peg_generator/pegen/parser.py
180
181
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,278
showpeek
def showpeek(self) -> str: tok = self._tokenizer.peek() return f"{tok.start[0]}.{tok.start[1]}: {token.tok_name[tok.type]}:{tok.string!r}"
python
Tools/peg_generator/pegen/parser.py
183
185
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,279
name
def name(self) -> Optional[tokenize.TokenInfo]: tok = self._tokenizer.peek() if tok.type == token.NAME and tok.string not in self.KEYWORDS: return self._tokenizer.getnext() return None
python
Tools/peg_generator/pegen/parser.py
188
192
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,280
number
def number(self) -> Optional[tokenize.TokenInfo]: tok = self._tokenizer.peek() if tok.type == token.NUMBER: return self._tokenizer.getnext() return None
python
Tools/peg_generator/pegen/parser.py
195
199
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,281
string
def string(self) -> Optional[tokenize.TokenInfo]: tok = self._tokenizer.peek() if tok.type == token.STRING: return self._tokenizer.getnext() return None
python
Tools/peg_generator/pegen/parser.py
202
206
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,282
op
def op(self) -> Optional[tokenize.TokenInfo]: tok = self._tokenizer.peek() if tok.type == token.OP: return self._tokenizer.getnext() return None
python
Tools/peg_generator/pegen/parser.py
209
213
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,283
type_comment
def type_comment(self) -> Optional[tokenize.TokenInfo]: tok = self._tokenizer.peek() if tok.type == token.TYPE_COMMENT: return self._tokenizer.getnext() return None
python
Tools/peg_generator/pegen/parser.py
216
220
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,284
soft_keyword
def soft_keyword(self) -> Optional[tokenize.TokenInfo]: tok = self._tokenizer.peek() if tok.type == token.NAME and tok.string in self.SOFT_KEYWORDS: return self._tokenizer.getnext() return None
python
Tools/peg_generator/pegen/parser.py
223
227
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,285
expect
def expect(self, type: str) -> Optional[tokenize.TokenInfo]: tok = self._tokenizer.peek() if tok.string == type: return self._tokenizer.getnext() if type in exact_token_types: if tok.type == exact_token_types[type]: return self._tokenizer.getnext() ...
python
Tools/peg_generator/pegen/parser.py
230
242
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,286
expect_forced
def expect_forced(self, res: Any, expectation: str) -> Optional[tokenize.TokenInfo]: if res is None: raise self.make_syntax_error(f"expected {expectation}") return res
python
Tools/peg_generator/pegen/parser.py
244
247
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,287
positive_lookahead
def positive_lookahead(self, func: Callable[..., T], *args: object) -> T: mark = self._mark() ok = func(*args) self._reset(mark) return ok
python
Tools/peg_generator/pegen/parser.py
249
253
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,288
negative_lookahead
def negative_lookahead(self, func: Callable[..., object], *args: object) -> bool: mark = self._mark() ok = func(*args) self._reset(mark) return not ok
python
Tools/peg_generator/pegen/parser.py
255
259
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,289
make_syntax_error
def make_syntax_error(self, message: str, filename: str = "<unknown>") -> SyntaxError: tok = self._tokenizer.diagnose() return SyntaxError(message, (filename, tok.start[0], 1 + tok.start[1], tok.line))
python
Tools/peg_generator/pegen/parser.py
261
263
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,290
simple_parser_main
def simple_parser_main(parser_class: Type[Parser]) -> None: argparser = argparse.ArgumentParser() argparser.add_argument( "-v", "--verbose", action="count", default=0, help="Print timing stats; repeat for more debug output", ) argparser.add_argument( "-q",...
python
Tools/peg_generator/pegen/parser.py
266
335
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,291
shorttok
def shorttok(tok: tokenize.TokenInfo) -> str: return "%-25.25s" % f"{tok.start[0]}.{tok.start[1]}: {token.tok_name[tok.type]}:{tok.string!r}"
python
Tools/peg_generator/pegen/tokenizer.py
10
11
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,292
__init__
def __init__( self, tokengen: Iterator[tokenize.TokenInfo], *, path: str = "", verbose: bool = False ): self._tokengen = tokengen self._tokens = [] self._index = 0 self._verbose = verbose self._lines: Dict[int, str] = {} self._path = path if verbose: ...
python
Tools/peg_generator/pegen/tokenizer.py
22
32
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,293
getnext
def getnext(self) -> tokenize.TokenInfo: """Return the next token and updates the index.""" cached = not self._index == len(self._tokens) tok = self.peek() self._index += 1 if self._verbose: self.report(cached, False) return tok
python
Tools/peg_generator/pegen/tokenizer.py
34
41
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,294
peek
def peek(self) -> tokenize.TokenInfo: """Return the next token *without* updating the index.""" while self._index == len(self._tokens): tok = next(self._tokengen) if tok.type in (tokenize.NL, tokenize.COMMENT): continue if tok.type == token.ERRORTOKEN ...
python
Tools/peg_generator/pegen/tokenizer.py
43
60
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,295
diagnose
def diagnose(self) -> tokenize.TokenInfo: if not self._tokens: self.getnext() return self._tokens[-1]
python
Tools/peg_generator/pegen/tokenizer.py
62
65
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,296
get_last_non_whitespace_token
def get_last_non_whitespace_token(self) -> tokenize.TokenInfo: for tok in reversed(self._tokens[: self._index]): if tok.type != tokenize.ENDMARKER and ( tok.type < tokenize.NEWLINE or tok.type > tokenize.DEDENT ): break return tok
python
Tools/peg_generator/pegen/tokenizer.py
67
73
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,297
get_lines
def get_lines(self, line_numbers: List[int]) -> List[str]: """Retrieve source lines corresponding to line numbers.""" if self._lines: lines = self._lines else: n = len(line_numbers) lines = {} count = 0 seen = 0 with open(se...
python
Tools/peg_generator/pegen/tokenizer.py
75
93
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,298
mark
def mark(self) -> Mark: return self._index
python
Tools/peg_generator/pegen/tokenizer.py
95
96
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,299
reset
def reset(self, index: Mark) -> None: if index == self._index: return assert 0 <= index <= len(self._tokens), (index, len(self._tokens)) old_index = self._index self._index = index if self._verbose: self.report(True, index < old_index)
python
Tools/peg_generator/pegen/tokenizer.py
98
105
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,300
report
def report(self, cached: bool, back: bool) -> None: if back: fill = "-" * self._index + "-" elif cached: fill = "-" * self._index + ">" else: fill = "-" * self._index + "*" if self._index == 0: print(f"{fill} (Bof)") else: ...
python
Tools/peg_generator/pegen/tokenizer.py
107
118
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }