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

Function parse_files

Tools/cases_generator/parser.py:42–78  ·  view source on GitHub ↗
(filenames: list[str])

Source from the content-addressed store, hash-verified

40
41
42def parse_files(filenames: list[str]) -> list[AstNode]:
43 result: list[AstNode] = []
44 for filename in filenames:
45 with open(filename) as file:
46 src = file.read()
47
48 psr = Parser(src, filename=prettify_filename(filename))
49
50 # Skip until begin marker
51 while tkn := psr.next(raw=True):
52 if tkn.text == BEGIN_MARKER:
53 break
54 else:
55 raise psr.make_syntax_error(
56 f"Couldn't find {BEGIN_MARKER!r} in {psr.filename}"
57 )
58 start = psr.getpos()
59
60 # Find end marker, then delete everything after it
61 while tkn := psr.next(raw=True):
62 if tkn.text == END_MARKER:
63 break
64 del psr.tokens[psr.getpos() - 1 :]
65
66 # Parse from start
67 psr.setpos(start)
68 thing_first_token = psr.peek()
69 while node := psr.definition():
70 assert node is not None
71 result.append(node) # type: ignore[arg-type]
72 if not psr.eof():
73 pprint.pprint(result)
74 psr.backup()
75 raise psr.make_syntax_error(
76 f"Extra stuff at the end of {filename}", psr.next(True)
77 )
78 return result

Callers

nothing calls this directly

Calls 14

make_syntax_errorMethod · 0.95
definitionMethod · 0.95
ParserClass · 0.90
prettify_filenameFunction · 0.85
eofMethod · 0.80
backupMethod · 0.80
openFunction · 0.50
readMethod · 0.45
nextMethod · 0.45
getposMethod · 0.45
setposMethod · 0.45
peekMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…