|
100 | 100 | #######################################
|
101 | 101 | # helpers
|
102 | 102 |
|
| 103 | +def iter_files(): |
| 104 | + for name in ('Modules', 'Objects', 'Parser', 'PC', 'Programs', 'Python'): |
| 105 | + root = os.path.join(ROOT, name) |
| 106 | + for dirname, _, files in os.walk(root): |
| 107 | + for name in files: |
| 108 | + if not name.endswith(('.c', '.h')): |
| 109 | + continue |
| 110 | + yield os.path.join(dirname, name) |
| 111 | + |
| 112 | + |
103 | 113 | def iter_global_strings():
|
104 | 114 | id_regex = re.compile(r'\b_Py_ID\((\w+)\)')
|
105 | 115 | str_regex = re.compile(r'\b_Py_DECLARE_STR\((\w+), "(.*?)"\)')
|
106 |
| - for dirname, _, files in os.walk(ROOT): |
107 |
| - if os.path.relpath(dirname, ROOT).startswith('Include'): |
108 |
| - continue |
109 |
| - for name in files: |
110 |
| - if not name.endswith(('.c', '.h')): |
111 |
| - continue |
112 |
| - filename = os.path.join(dirname, name) |
113 |
| - with open(os.path.join(filename), encoding='utf-8') as infile: |
114 |
| - for lno, line in enumerate(infile, 1): |
115 |
| - for m in id_regex.finditer(line): |
116 |
| - identifier, = m.groups() |
117 |
| - yield identifier, None, filename, lno, line |
118 |
| - for m in str_regex.finditer(line): |
119 |
| - varname, string = m.groups() |
120 |
| - yield varname, string, filename, lno, line |
| 116 | + for filename in iter_files(): |
| 117 | + with open(filename, encoding='utf-8') as infile: |
| 118 | + for lno, line in enumerate(infile, 1): |
| 119 | + for m in id_regex.finditer(line): |
| 120 | + identifier, = m.groups() |
| 121 | + yield identifier, None, filename, lno, line |
| 122 | + for m in str_regex.finditer(line): |
| 123 | + varname, string = m.groups() |
| 124 | + yield varname, string, filename, lno, line |
121 | 125 |
|
122 | 126 | def iter_to_marker(lines, marker):
|
123 | 127 | for line in lines:
|
|
0 commit comments