forked from leanprover-community/lftcm2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk_exercises.py
executable file
·31 lines (25 loc) · 934 Bytes
/
mk_exercises.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
import regex
from pathlib import Path
sorry_regex = regex.compile(r'(.*)-- sorry.*')
root = Path(__file__).parent/'src'
if __name__ == '__main__':
for path in (root/'solutions').glob('**/*.lean'):
print(path)
out = root/'exercises_sources'/path.relative_to(root/'solutions')
out.parent.mkdir(exist_ok=True)
with out.open('w') as outp:
with path.open() as inp:
state = 'normal'
for line in inp:
m = sorry_regex.match(line)
if state == 'normal':
if m:
state = 'sorry'
else:
outp.write(line)
else:
if m:
state = 'normal'
outp.write(m.group(1)+ 'sorry\n')
outp.write('\n')