MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Tools/peg_generator/pegen/keywordgen.py:39–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37
38
39def main() -> None:
40 parser = argparse.ArgumentParser(
41 description="Generate the Lib/keywords.py file from the grammar."
42 )
43 parser.add_argument(
44 "grammar", help="The file with the grammar definition in PEG format"
45 )
46 parser.add_argument(
47 "tokens_file", help="The file with the token definitions"
48 )
49 parser.add_argument(
50 "keyword_file",
51 help="The path to write the keyword definitions",
52 )
53 args = parser.parse_args()
54
55 grammar, _, _ = build_parser(args.grammar)
56 with open(args.tokens_file) as tok_file:
57 all_tokens, exact_tok, non_exact_tok = generate_token_definitions(tok_file)
58 gen = CParserGenerator(grammar, all_tokens, exact_tok, non_exact_tok, file=None)
59 gen.collect_rules()
60
61 with open(args.keyword_file, 'w') as thefile:
62 all_keywords = sorted(list(gen.keywords.keys()))
63 all_soft_keywords = sorted(gen.soft_keywords)
64
65 keywords = "" if not all_keywords else " " + ",\n ".join(map(repr, all_keywords))
66 soft_keywords = (
67 "" if not all_soft_keywords else " " + ",\n ".join(map(repr, all_soft_keywords))
68 )
69 thefile.write(TEMPLATE.format(keywords=keywords, soft_keywords=soft_keywords))
70
71
72if __name__ == "__main__":

Callers 1

keywordgen.pyFile · 0.70

Calls 12

parse_argsMethod · 0.95
build_parserFunction · 0.85
CParserGeneratorClass · 0.85
listClass · 0.85
collect_rulesMethod · 0.80
openFunction · 0.50
add_argumentMethod · 0.45
keysMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…