Created
September 25, 2012 16:32
-
-
Save graydon/3782995 to your computer and use it in GitHub Desktop.
This file contains 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/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