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

Function main

Tools/peg_generator/pegen/__main__.py:129–186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127
128
129def main() -> None:
130 from pegen.testutil import print_memstats
131
132 args = argparser.parse_args()
133 if "func" not in args:
134 argparser.error("Must specify the target language mode ('c' or 'python')")
135
136 t0 = time.time()
137 grammar, parser, tokenizer, gen = args.func(args)
138 t1 = time.time()
139
140 validate_grammar(grammar)
141
142 if not args.quiet:
143 if args.verbose:
144 print("Raw Grammar:")
145 for line in repr(grammar).splitlines():
146 print(" ", line)
147
148 print("Clean Grammar:")
149 for line in str(grammar).splitlines():
150 print(" ", line)
151
152 if args.verbose:
153 print("First Graph:")
154 for src, dsts in gen.first_graph.items():
155 print(f" {src} -> {', '.join(dsts)}")
156 print("First SCCS:")
157 for scc in gen.first_sccs:
158 print(" ", scc, end="")
159 if len(scc) > 1:
160 print(
161 " # Indirectly left-recursive; leaders:",
162 {name for name in scc if grammar.rules[name].leader},
163 )
164 else:
165 name = next(iter(scc))
166 if name in gen.first_graph[name]:
167 print(" # Left-recursive")
168 else:
169 print()
170
171 if args.verbose:
172 dt = t1 - t0
173 diag = tokenizer.diagnose()
174 nlines = diag.end[0]
175 if diag.type == token.ENDMARKER:
176 nlines -= 1
177 print(f"Total time: {dt:.3f} sec; {nlines} lines", end="")
178 if dt:
179 print(f"; {nlines / dt:.0f} lines/sec")
180 else:
181 print()
182 print("Caches sizes:")
183 print(f" token array : {len(tokenizer._tokens):10}")
184 print(f" cache : {len(parser._cache):10}")
185 if not print_memstats():
186 print("(Can't find psutil; install it for memory stats.)")

Callers 1

__main__.pyFile · 0.70

Calls 11

validate_grammarFunction · 0.90
print_memstatsFunction · 0.90
strFunction · 0.85
diagnoseMethod · 0.80
parse_argsMethod · 0.45
errorMethod · 0.45
timeMethod · 0.45
funcMethod · 0.45
splitlinesMethod · 0.45
itemsMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…