lean4-htt/script/do_uppers.py
2019-03-21 15:06:43 -07:00

20 lines
706 B
Python
Executable file

#!/usr/bin/env python3
import regex as re
import os
import sys
# https://stackoverflow.com/a/19053800
def to_camel_case(snake_str):
components = snake_str.split('_')
# We capitalize the first letter of each component except the first one
# with the 'title' method and join them together.
return components[0] + ''.join(x.title() for x in components[1:])
uppers = set(s.strip() for s in open('script/uppers').readlines())
candidate = re.compile(r"(?!type class|monad transformer)\w+", re.MULTILINE)
fpath = sys.argv[1]
with open(fpath) as f:
s = f.read()
s = candidate.sub(lambda w: w[0][0].upper() + w[0][1:] if w[0] in uppers else w[0], s)
with open(fpath, "w") as f:
f.write(s)