Last active
June 1, 2019 05:39
-
-
Save louisswarren/47b5b533803ff48b380b9df349307099 to your computer and use it in GitHub Desktop.
Strip literate agda down to agda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
def get_code_lines(lines): | |
in_code = False | |
for line in lines: | |
if line.startswith(r'\begin{code}'): | |
in_code = True | |
yield '--STRIP: ' | |
elif line.startswith(r'\end{code}'): | |
in_code = False | |
yield '--STRIP: ' | |
elif not in_code or line.startswith(r'module '): | |
yield '--STRIP: ' | |
yield line | |
def strip(fname): | |
assert(fname[-6:] == '.lagda') | |
oname = fname[:-6] + '-stripped.agda' | |
with open(fname) as f: | |
lines = f.readlines() | |
with open(oname, 'w') as f: | |
for line in get_code_lines(lines): | |
f.write(line) | |
if __name__ == '__main__': | |
strip('Formula.lagda') | |
for x in sys.argv[1:]: | |
strip(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment