Skip to content

Instantly share code, notes, and snippets.

@graydon
Created Sep 25, 2012
Embed
What would you like to do?
#!/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