Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
leanprover-community
GitHub Repository: leanprover-community/tutorials
Path: blob/master/mk_exercises.py
212 views
1
#!/usr/bin/env python3
2
3
import re
4
from pathlib import Path
5
6
sorry_regex = re.compile(r'(.*)-- sorry.*')
7
root = Path(__file__).parent/'src'
8
9
if __name__ == '__main__':
10
for path in (root/'solutions').glob('**/*.lean'):
11
if path.name == 'tuto_lib.lean':
12
continue
13
print(path)
14
out = root/'exercises'/path.relative_to(root/'solutions')
15
with out.open('w') as outp:
16
with path.open() as inp:
17
state = 'normal'
18
for line in inp:
19
m = sorry_regex.match(line)
20
if state == 'normal':
21
if m:
22
state = 'sorry'
23
else:
24
outp.write(line)
25
else:
26
if m:
27
state = 'normal'
28
outp.write(m.group(1)+ 'sorry\n')
29
30
outp.write('\n')
31
32
33
34