Skip to content

Instantly share code, notes, and snippets.

@graydon
Created September 25, 2012 16:32
Show Gist options
  • Save graydon/3782995 to your computer and use it in GitHub Desktop.
Save graydon/3782995 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import fileinput, re, sys
current_file = None
current_exports = []
def fixup(m):
global current_exports
if m.group(2) in current_exports:
return "pub " + m.group(1) + " " + m.group(2)
else:
return m.group(0)
for line in fileinput.input(inplace=1, backup=".bak"):
if current_file != fileinput.filename():
current_file = fileinput.filename()
current_exports = []
m = re.search('^ *export (.*);', line)
if m:
current_exports += re.split(' *, *', m.group(1))
else:
sys.stdout.write(re.sub('((?:pure *|unsafe *)?fn|type|enum|mod|trait|const) *(\w+)', fixup, line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment