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,101
fulldisplayname
def fulldisplayname(self) -> str: parent: Class | Module | Clinic | None if self.kind.new_or_init: parent = getattr(self.cls, "parent", None) else: parent = self.parent name = self.displayname while isinstance(parent, (Module, Class)): name = f...
python
Tools/clinic/libclinic/function.py
129
139
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,102
render_parameters
def render_parameters(self) -> list[Parameter]: if not self.__render_parameters__: l: list[Parameter] = [] self.__render_parameters__ = l for p in self.parameters.values(): p = p.copy() p.converter.pre_render() l.append(p) ...
python
Tools/clinic/libclinic/function.py
142
150
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,103
methoddef_flags
def methoddef_flags(self) -> str | None: if self.kind.new_or_init: return None flags = [] match self.kind: case FunctionKind.CLASS_METHOD: flags.append('METH_CLASS') case FunctionKind.STATIC_METHOD: flags.append('METH_STATIC') ...
python
Tools/clinic/libclinic/function.py
153
167
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,104
__repr__
def __repr__(self) -> str: return f'<clinic.Function {self.name!r}>'
python
Tools/clinic/libclinic/function.py
169
170
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,105
copy
def copy(self, **overrides: Any) -> Function: f = dc.replace(self, **overrides) f.parameters = { name: value.copy(function=f) for name, value in f.parameters.items() } return f
python
Tools/clinic/libclinic/function.py
172
178
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,106
__repr__
def __repr__(self) -> str: return f'<clinic.Parameter {self.name!r}>'
python
Tools/clinic/libclinic/function.py
200
201
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,107
is_keyword_only
def is_keyword_only(self) -> bool: return self.kind == inspect.Parameter.KEYWORD_ONLY
python
Tools/clinic/libclinic/function.py
203
204
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,108
is_positional_only
def is_positional_only(self) -> bool: return self.kind == inspect.Parameter.POSITIONAL_ONLY
python
Tools/clinic/libclinic/function.py
206
207
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,109
is_vararg
def is_vararg(self) -> bool: return self.kind == inspect.Parameter.VAR_POSITIONAL
python
Tools/clinic/libclinic/function.py
209
210
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,110
is_optional
def is_optional(self) -> bool: return not self.is_vararg() and (self.default is not unspecified)
python
Tools/clinic/libclinic/function.py
212
213
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,111
copy
def copy( self, /, *, converter: CConverter | None = None, function: Function | None = None, **overrides: Any ) -> Parameter: function = function or self.function if not converter: converter = copy.copy(self.converter) converter...
python
Tools/clinic/libclinic/function.py
215
227
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,112
get_displayname
def get_displayname(self, i: int) -> str: if i == 0: return 'argument' if not self.is_positional_only(): return f'argument {self.name!r}' else: return f'argument {i}'
python
Tools/clinic/libclinic/function.py
229
235
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,113
render_docstring
def render_docstring(self) -> str: lines = [f" {self.name}"] lines.extend(f" {line}" for line in self.docstring.split("\n")) return "\n".join(lines).rstrip()
python
Tools/clinic/libclinic/function.py
237
240
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,114
permute_left_option_groups
def permute_left_option_groups( l: Sequence[Iterable[Parameter]] ) -> Iterator[ParamTuple]: """ Given [(1,), (2,), (3,)], should yield: () (3,) (2, 3) (1, 2, 3) """ yield tuple() accumulator: list[Parameter] = [] for group in reversed(l): accumulator = lis...
python
Tools/clinic/libclinic/function.py
246
260
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,115
permute_right_option_groups
def permute_right_option_groups( l: Sequence[Iterable[Parameter]] ) -> Iterator[ParamTuple]: """ Given [(1,), (2,), (3,)], should yield: () (1,) (1, 2) (1, 2, 3) """ yield tuple() accumulator: list[Parameter] = [] for group in l: accumulator.extend(group) ...
python
Tools/clinic/libclinic/function.py
263
277
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,116
permute_optional_groups
def permute_optional_groups( left: Sequence[Iterable[Parameter]], required: Iterable[Parameter], right: Sequence[Iterable[Parameter]] ) -> tuple[ParamTuple, ...]: """ Generator function that computes the set of acceptable argument lists for the provided iterables of argument groups. (Actual...
python
Tools/clinic/libclinic/function.py
280
310
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,117
__init__
def __init__(self, transitions, type_indices, ttis, abbrs): self.transitions = transitions self.type_indices = type_indices self.ttis = ttis self.abbrs = abbrs
python
Tools/tz/zdump.py
11
15
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,118
fromfile
def fromfile(cls, fileobj): if fileobj.read(4).decode() != "TZif": raise ValueError("not a zoneinfo file") fileobj.seek(20) header = fileobj.read(24) tzh = (tzh_ttisgmtcnt, tzh_ttisstdcnt, tzh_leapcnt, tzh_timecnt, tzh_typecnt, tzh_charcnt) = struct.unpack(">6l...
python
Tools/tz/zdump.py
18
42
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,119
dump
def dump(self, stream, start=None, end=None): for j, (trans, i) in enumerate(zip(self.transitions, self.type_indices)): utc = datetime.utcfromtimestamp(trans) tti = self.ttis[i] lmt = datetime.utcfromtimestamp(trans + tti.tt_gmtoff) abbrind = tti.tt_abbrind ...
python
Tools/tz/zdump.py
44
56
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,120
zonelist
def zonelist(cls, zonedir='/usr/share/zoneinfo'): zones = [] for root, _, files in os.walk(zonedir): for f in files: p = os.path.join(root, f) with open(p, 'rb') as o: magic = o.read(4) if magic == b'TZif': ...
python
Tools/tz/zdump.py
59
68
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,121
__init__
def __init__(self, grammar: grammar.Grammar) -> None: self.grammar = grammar self.rulename: Optional[str] = None
python
Tools/peg_generator/pegen/validator.py
12
14
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,122
validate_rule
def validate_rule(self, rulename: str, node: Rule) -> None: self.rulename = rulename self.visit(node) self.rulename = None
python
Tools/peg_generator/pegen/validator.py
16
19
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,123
visit_Rhs
def visit_Rhs(self, node: Rhs) -> None: for index, alt in enumerate(node.alts): alts_to_consider = node.alts[index + 1 :] for other_alt in alts_to_consider: self.check_intersection(alt, other_alt)
python
Tools/peg_generator/pegen/validator.py
23
27
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,124
check_intersection
def check_intersection(self, first_alt: Alt, second_alt: Alt) -> None: if str(second_alt).startswith(str(first_alt)): raise ValidationError( f"In {self.rulename} there is an alternative that will " f"never be visited:\n{second_alt}" )
python
Tools/peg_generator/pegen/validator.py
29
34
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,125
validate_grammar
def validate_grammar(the_grammar: grammar.Grammar) -> None: for validator_cls in GrammarValidator.__subclasses__(): validator = validator_cls(the_grammar) for rule_name, rule in the_grammar.rules.items(): validator.validate_rule(rule_name, rule)
python
Tools/peg_generator/pegen/validator.py
37
41
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,126
get_extra_flags
def get_extra_flags(compiler_flags: str, compiler_py_flags_nodist: str) -> List[str]: flags = sysconfig.get_config_var(compiler_flags) py_flags_nodist = sysconfig.get_config_var(compiler_py_flags_nodist) if flags is None or py_flags_nodist is None: return [] return f"{flags} {py_flags_nodist}".s...
python
Tools/peg_generator/pegen/build.py
25
30
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,127
fixup_build_ext
def fixup_build_ext(cmd: Incomplete) -> None: """Function needed to make build_ext tests pass. When Python was built with --enable-shared on Unix, -L. is not enough to find libpython<blah>.so, because regrtest runs in a tempdir, not in the source directory where the .so lives. When Python was buil...
python
Tools/peg_generator/pegen/build.py
33
69
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,128
compile_c_extension
def compile_c_extension( generated_source_path: str, build_dir: Optional[str] = None, verbose: bool = False, keep_asserts: bool = True, disable_optimization: bool = False, library_dir: Optional[str] = None, ) -> pathlib.Path: """Compile the generated source for a parser generator into an ext...
python
Tools/peg_generator/pegen/build.py
72
237
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,129
build_parser
def build_parser( grammar_file: str, verbose_tokenizer: bool = False, verbose_parser: bool = False ) -> Tuple[Grammar, Parser, Tokenizer]: with open(grammar_file) as file: tokenizer = Tokenizer(tokenize.generate_tokens(file.readline), verbose=verbose_tokenizer) parser = GrammarParser(tokenizer, ...
python
Tools/peg_generator/pegen/build.py
240
251
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,130
generate_token_definitions
def generate_token_definitions(tokens: IO[str]) -> TokenDefinitions: all_tokens = {} exact_tokens = {} non_exact_tokens = set() numbers = itertools.count(0) for line in tokens: line = line.strip() if not line or line.startswith("#"): continue pieces = line.spli...
python
Tools/peg_generator/pegen/build.py
254
280
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,131
build_c_generator
def build_c_generator( grammar: Grammar, grammar_file: str, tokens_file: str, output_file: str, compile_extension: bool = False, verbose_c_extension: bool = False, keep_asserts_in_extension: bool = True, skip_actions: bool = False, ) -> ParserGenerator: with open(tokens_file, "r") as...
python
Tools/peg_generator/pegen/build.py
283
309
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,132
build_python_generator
def build_python_generator( grammar: Grammar, grammar_file: str, output_file: str, skip_actions: bool = False, ) -> ParserGenerator: with open(output_file, "w") as file: gen: ParserGenerator = PythonParserGenerator(grammar, file) # TODO: skip_actions gen.generate(grammar_file) r...
python
Tools/peg_generator/pegen/build.py
312
321
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,133
build_c_parser_and_generator
def build_c_parser_and_generator( grammar_file: str, tokens_file: str, output_file: str, compile_extension: bool = False, verbose_tokenizer: bool = False, verbose_parser: bool = False, verbose_c_extension: bool = False, keep_asserts_in_extension: bool = True, skip_actions: bool = Fal...
python
Tools/peg_generator/pegen/build.py
324
365
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,134
build_python_parser_and_generator
def build_python_parser_and_generator( grammar_file: str, output_file: str, verbose_tokenizer: bool = False, verbose_parser: bool = False, skip_actions: bool = False, ) -> Tuple[Grammar, Parser, Tokenizer, ParserGenerator]: """Generate rules, python parser, tokenizer, parser generator for a give...
python
Tools/peg_generator/pegen/build.py
368
393
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,135
__init__
def __init__(self, rules: Dict[str, Rule], callmakervisitor: GrammarVisitor) -> None: self.rulses = rules self.callmaker = callmakervisitor
python
Tools/peg_generator/pegen/parser_generator.py
46
48
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,136
visit_Rule
def visit_Rule(self, rule: Rule) -> None: self.visit(rule.flatten())
python
Tools/peg_generator/pegen/parser_generator.py
50
51
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,137
visit_NamedItem
def visit_NamedItem(self, item: NamedItem) -> None: self.callmaker.visit(item)
python
Tools/peg_generator/pegen/parser_generator.py
53
54
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,138
__init__
def __init__(self, gen: "ParserGenerator", keywords: Dict[str, int], soft_keywords: Set[str]): self.generator = gen self.keywords = keywords self.soft_keywords = soft_keywords
python
Tools/peg_generator/pegen/parser_generator.py
60
63
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,139
visit_StringLeaf
def visit_StringLeaf(self, node: StringLeaf) -> None: val = ast.literal_eval(node.value) if re.match(r"[a-zA-Z_]\w*\Z", val): # This is a keyword if node.value.endswith("'") and node.value not in self.keywords: self.keywords[val] = self.generator.keyword_type() e...
python
Tools/peg_generator/pegen/parser_generator.py
65
71
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,140
__init__
def __init__(self, rules: Dict[str, Rule], tokens: Set[str]): self.rules = rules self.tokens = tokens
python
Tools/peg_generator/pegen/parser_generator.py
75
77
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,141
visit_NameLeaf
def visit_NameLeaf(self, node: NameLeaf) -> None: if node.value not in self.rules and node.value not in self.tokens: raise GrammarError(f"Dangling reference to rule {node.value!r}")
python
Tools/peg_generator/pegen/parser_generator.py
79
81
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,142
visit_NamedItem
def visit_NamedItem(self, node: NamedItem) -> None: if node.name and node.name.startswith("_"): raise GrammarError(f"Variable names cannot start with underscore: '{node.name}'") self.visit(node.item)
python
Tools/peg_generator/pegen/parser_generator.py
83
86
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,143
__init__
def __init__(self, grammar: Grammar, tokens: Set[str], file: Optional[IO[Text]]): self.grammar = grammar self.tokens = tokens self.keywords: Dict[str, int] = {} self.soft_keywords: Set[str] = set() self.rules = grammar.rules self.validate_rule_names() if "trailer"...
python
Tools/peg_generator/pegen/parser_generator.py
92
110
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,144
validate_rule_names
def validate_rule_names(self) -> None: for rule in self.rules: if rule.startswith("_"): raise GrammarError(f"Rule names cannot start with underscore: '{rule}'")
python
Tools/peg_generator/pegen/parser_generator.py
112
115
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,145
local_variable_context
def local_variable_context(self) -> Iterator[None]: self._local_variable_stack.append([]) yield self._local_variable_stack.pop()
python
Tools/peg_generator/pegen/parser_generator.py
118
121
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,146
local_variable_names
def local_variable_names(self) -> List[str]: return self._local_variable_stack[-1]
python
Tools/peg_generator/pegen/parser_generator.py
124
125
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,147
generate
def generate(self, filename: str) -> None: raise NotImplementedError
python
Tools/peg_generator/pegen/parser_generator.py
128
129
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,148
indent
def indent(self) -> Iterator[None]: self.level += 1 try: yield finally: self.level -= 1
python
Tools/peg_generator/pegen/parser_generator.py
132
137
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,149
print
def print(self, *args: object) -> None: if not args: print(file=self.file) else: print(" " * self.level, end="", file=self.file) print(*args, file=self.file)
python
Tools/peg_generator/pegen/parser_generator.py
139
144
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,150
printblock
def printblock(self, lines: str) -> None: for line in lines.splitlines(): self.print(line)
python
Tools/peg_generator/pegen/parser_generator.py
146
148
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,151
collect_rules
def collect_rules(self) -> None: keyword_collector = KeywordCollectorVisitor(self, self.keywords, self.soft_keywords) for rule in self.all_rules.values(): keyword_collector.visit(rule) rule_collector = RuleCollectorVisitor(self.rules, self.callmakervisitor) done: Set[str] = ...
python
Tools/peg_generator/pegen/parser_generator.py
150
164
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,152
keyword_type
def keyword_type(self) -> int: self.keyword_counter += 1 return self.keyword_counter
python
Tools/peg_generator/pegen/parser_generator.py
166
168
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,153
artifical_rule_from_rhs
def artifical_rule_from_rhs(self, rhs: Rhs) -> str: self.counter += 1 name = f"_tmp_{self.counter}" # TODO: Pick a nicer name. self.all_rules[name] = Rule(name, None, rhs) return name
python
Tools/peg_generator/pegen/parser_generator.py
170
174
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,154
artificial_rule_from_repeat
def artificial_rule_from_repeat(self, node: Plain, is_repeat1: bool) -> str: self.counter += 1 if is_repeat1: prefix = "_loop1_" else: prefix = "_loop0_" name = f"{prefix}{self.counter}" self.all_rules[name] = Rule(name, None, Rhs([Alt([NamedItem(None, nod...
python
Tools/peg_generator/pegen/parser_generator.py
176
184
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,155
artifical_rule_from_gather
def artifical_rule_from_gather(self, node: Gather) -> str: self.counter += 1 name = f"_gather_{self.counter}" self.counter += 1 extra_function_name = f"_loop0_{self.counter}" extra_function_alt = Alt( [NamedItem(None, node.separator), NamedItem("elem", node.node)], ...
python
Tools/peg_generator/pegen/parser_generator.py
186
208
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,156
dedupe
def dedupe(self, name: str) -> str: origname = name counter = 0 while name in self.local_variable_names: counter += 1 name = f"{origname}_{counter}" self.local_variable_names.append(name) return name
python
Tools/peg_generator/pegen/parser_generator.py
210
217
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,157
__init__
def __init__(self, rules: Dict[str, Rule]) -> None: self.rules = rules self.visited: Set[Any] = set() self.nullables: Set[Union[Rule, NamedItem]] = set()
python
Tools/peg_generator/pegen/parser_generator.py
221
224
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,158
visit_Rule
def visit_Rule(self, rule: Rule) -> bool: if rule in self.visited: return False self.visited.add(rule) if self.visit(rule.rhs): self.nullables.add(rule) return rule in self.nullables
python
Tools/peg_generator/pegen/parser_generator.py
226
232
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,159
visit_Rhs
def visit_Rhs(self, rhs: Rhs) -> bool: for alt in rhs.alts: if self.visit(alt): return True return False
python
Tools/peg_generator/pegen/parser_generator.py
234
238
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,160
visit_Alt
def visit_Alt(self, alt: Alt) -> bool: for item in alt.items: if not self.visit(item): return False return True
python
Tools/peg_generator/pegen/parser_generator.py
240
244
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,161
visit_Forced
def visit_Forced(self, force: Forced) -> bool: return True
python
Tools/peg_generator/pegen/parser_generator.py
246
247
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,162
visit_LookAhead
def visit_LookAhead(self, lookahead: Lookahead) -> bool: return True
python
Tools/peg_generator/pegen/parser_generator.py
249
250
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,163
visit_Opt
def visit_Opt(self, opt: Opt) -> bool: return True
python
Tools/peg_generator/pegen/parser_generator.py
252
253
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,164
visit_Repeat0
def visit_Repeat0(self, repeat: Repeat0) -> bool: return True
python
Tools/peg_generator/pegen/parser_generator.py
255
256
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,165
visit_Repeat1
def visit_Repeat1(self, repeat: Repeat1) -> bool: return False
python
Tools/peg_generator/pegen/parser_generator.py
258
259
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,166
visit_Gather
def visit_Gather(self, gather: Gather) -> bool: return False
python
Tools/peg_generator/pegen/parser_generator.py
261
262
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,167
visit_Cut
def visit_Cut(self, cut: Cut) -> bool: return False
python
Tools/peg_generator/pegen/parser_generator.py
264
265
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,168
visit_Group
def visit_Group(self, group: Group) -> bool: return self.visit(group.rhs)
python
Tools/peg_generator/pegen/parser_generator.py
267
268
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,169
visit_NamedItem
def visit_NamedItem(self, item: NamedItem) -> bool: if self.visit(item.item): self.nullables.add(item) return item in self.nullables
python
Tools/peg_generator/pegen/parser_generator.py
270
273
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,170
visit_NameLeaf
def visit_NameLeaf(self, node: NameLeaf) -> bool: if node.value in self.rules: return self.visit(self.rules[node.value]) # Token or unknown; never empty. return False
python
Tools/peg_generator/pegen/parser_generator.py
275
279
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,171
visit_StringLeaf
def visit_StringLeaf(self, node: StringLeaf) -> bool: # The string token '' is considered empty. return not node.value
python
Tools/peg_generator/pegen/parser_generator.py
281
283
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,172
compute_nullables
def compute_nullables(rules: Dict[str, Rule]) -> Set[Any]: """Compute which rules in a grammar are nullable. Thanks to TatSu (tatsu/leftrec.py) for inspiration. """ nullable_visitor = NullableVisitor(rules) for rule in rules.values(): nullable_visitor.visit(rule) return nullable_visitor...
python
Tools/peg_generator/pegen/parser_generator.py
286
294
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,173
__init__
def __init__(self, rules: Dict[str, Rule]) -> None: self.rules = rules self.nullables = compute_nullables(rules)
python
Tools/peg_generator/pegen/parser_generator.py
298
300
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,174
generic_visit
def generic_visit(self, node: Iterable[Any], *args: Any, **kwargs: Any) -> Set[Any]: names: Set[str] = set() for value in node: if isinstance(value, list): for item in value: names |= self.visit(item, *args, **kwargs) else: name...
python
Tools/peg_generator/pegen/parser_generator.py
302
310
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,175
visit_Alt
def visit_Alt(self, alt: Alt) -> Set[Any]: names: Set[str] = set() for item in alt.items: names |= self.visit(item) if item not in self.nullables: break return names
python
Tools/peg_generator/pegen/parser_generator.py
312
318
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,176
visit_Forced
def visit_Forced(self, force: Forced) -> Set[Any]: return set()
python
Tools/peg_generator/pegen/parser_generator.py
320
321
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,177
visit_LookAhead
def visit_LookAhead(self, lookahead: Lookahead) -> Set[Any]: return set()
python
Tools/peg_generator/pegen/parser_generator.py
323
324
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,178
visit_Cut
def visit_Cut(self, cut: Cut) -> Set[Any]: return set()
python
Tools/peg_generator/pegen/parser_generator.py
326
327
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,179
visit_NameLeaf
def visit_NameLeaf(self, node: NameLeaf) -> Set[Any]: return {node.value}
python
Tools/peg_generator/pegen/parser_generator.py
329
330
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,180
visit_StringLeaf
def visit_StringLeaf(self, node: StringLeaf) -> Set[Any]: return set()
python
Tools/peg_generator/pegen/parser_generator.py
332
333
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,181
compute_left_recursives
def compute_left_recursives( rules: Dict[str, Rule] ) -> Tuple[Dict[str, AbstractSet[str]], List[AbstractSet[str]]]: graph = make_first_graph(rules) sccs = list(sccutils.strongly_connected_components(graph.keys(), graph)) for scc in sccs: if len(scc) > 1: for name in scc: ...
python
Tools/peg_generator/pegen/parser_generator.py
336
363
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,182
make_first_graph
def make_first_graph(rules: Dict[str, Rule]) -> Dict[str, AbstractSet[str]]: """Compute the graph of left-invocations. There's an edge from A to B if A may invoke B at its initial position. Note that this requires the nullable flags to have been computed. """ initial_name_visitor = InitialName...
python
Tools/peg_generator/pegen/parser_generator.py
366
382
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,183
__init__
def __init__(self, rules: Dict[str, Rule]) -> None: self.rules = rules self.nullables = compute_nullables(rules) self.first_sets: Dict[str, Set[str]] = dict() self.in_process: Set[str] = set()
python
Tools/peg_generator/pegen/first_sets.py
36
40
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,184
calculate
def calculate(self) -> Dict[str, Set[str]]: for name, rule in self.rules.items(): self.visit(rule) return self.first_sets
python
Tools/peg_generator/pegen/first_sets.py
42
45
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,185
visit_Alt
def visit_Alt(self, item: Alt) -> Set[str]: result: Set[str] = set() to_remove: Set[str] = set() for other in item.items: new_terminals = self.visit(other) if isinstance(other.item, NegativeLookahead): to_remove |= new_terminals result |= new_t...
python
Tools/peg_generator/pegen/first_sets.py
47
72
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,186
visit_Cut
def visit_Cut(self, item: Cut) -> Set[str]: return set()
python
Tools/peg_generator/pegen/first_sets.py
74
75
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,187
visit_Group
def visit_Group(self, item: Group) -> Set[str]: return self.visit(item.rhs)
python
Tools/peg_generator/pegen/first_sets.py
77
78
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,188
visit_PositiveLookahead
def visit_PositiveLookahead(self, item: Lookahead) -> Set[str]: return self.visit(item.node)
python
Tools/peg_generator/pegen/first_sets.py
80
81
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,189
visit_NegativeLookahead
def visit_NegativeLookahead(self, item: NegativeLookahead) -> Set[str]: return self.visit(item.node)
python
Tools/peg_generator/pegen/first_sets.py
83
84
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,190
visit_NamedItem
def visit_NamedItem(self, item: NamedItem) -> Set[str]: return self.visit(item.item)
python
Tools/peg_generator/pegen/first_sets.py
86
87
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,191
visit_Opt
def visit_Opt(self, item: Opt) -> Set[str]: return self.visit(item.node)
python
Tools/peg_generator/pegen/first_sets.py
89
90
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,192
visit_Gather
def visit_Gather(self, item: Gather) -> Set[str]: return self.visit(item.node)
python
Tools/peg_generator/pegen/first_sets.py
92
93
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,193
visit_Repeat0
def visit_Repeat0(self, item: Repeat0) -> Set[str]: return self.visit(item.node)
python
Tools/peg_generator/pegen/first_sets.py
95
96
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,194
visit_Repeat1
def visit_Repeat1(self, item: Repeat1) -> Set[str]: return self.visit(item.node)
python
Tools/peg_generator/pegen/first_sets.py
98
99
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,195
visit_NameLeaf
def visit_NameLeaf(self, item: NameLeaf) -> Set[str]: if item.value not in self.rules: return {item.value} if item.value not in self.first_sets: self.first_sets[item.value] = self.visit(self.rules[item.value]) return self.first_sets[item.value] elif item.valu...
python
Tools/peg_generator/pegen/first_sets.py
101
111
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,196
visit_StringLeaf
def visit_StringLeaf(self, item: StringLeaf) -> Set[str]: return {item.value}
python
Tools/peg_generator/pegen/first_sets.py
113
114
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,197
visit_Rhs
def visit_Rhs(self, item: Rhs) -> Set[str]: result: Set[str] = set() for alt in item.alts: result |= self.visit(alt) return result
python
Tools/peg_generator/pegen/first_sets.py
116
120
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,198
visit_Rule
def visit_Rule(self, item: Rule) -> Set[str]: if item.name in self.in_process: return set() elif item.name not in self.first_sets: self.in_process.add(item.name) terminals = self.visit(item.rhs) if item in self.nullables: terminals.add("") ...
python
Tools/peg_generator/pegen/first_sets.py
122
132
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,199
main
def main() -> None: args = argparser.parse_args() try: grammar, parser, tokenizer = build_parser(args.grammar_file) except Exception as err: print("ERROR: Failed to parse grammar file", file=sys.stderr) sys.exit(1) firs_sets = FirstSetCalculator(grammar.rules).calculate() p...
python
Tools/peg_generator/pegen/first_sets.py
135
145
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,200
children
def children(self, node: Rule) -> Iterator[Any]: for value in node: if isinstance(value, list): yield from value else: yield value
python
Tools/peg_generator/pegen/grammar_visualizer.py
15
20
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }