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

Function generate_token_definitions

Tools/peg_generator/pegen/build.py:255–281  ·  view source on GitHub ↗
(tokens: IO[str])

Source from the content-addressed store, hash-verified

253
254
255def generate_token_definitions(tokens: IO[str]) -> TokenDefinitions:
256 all_tokens = {}
257 exact_tokens = {}
258 non_exact_tokens = set()
259 numbers = itertools.count(0)
260
261 for line in tokens:
262 line = line.strip()
263
264 if not line or line.startswith("#"):
265 continue
266
267 pieces = line.split()
268 index = next(numbers)
269
270 if len(pieces) == 1:
271 (token,) = pieces
272 non_exact_tokens.add(token)
273 all_tokens[index] = token
274 elif len(pieces) == 2:
275 token, op = pieces
276 exact_tokens[op.strip("'")] = index
277 all_tokens[index] = token
278 else:
279 raise ValueError(f"Unexpected line found in Tokens file: {line}")
280
281 return all_tokens, exact_tokens, non_exact_tokens
282
283
284def build_c_generator(

Callers 2

build_c_generatorFunction · 0.85
mainFunction · 0.85

Calls 6

setFunction · 0.85
countMethod · 0.45
stripMethod · 0.45
startswithMethod · 0.45
splitMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…