antlr3/antlr-clean-generated

24 lines
679 B
Python

#!/usr/bin/python
# Clean out files which look to have been generated by antlr
# Author: Colin Walters <walters@verbum.org>
# This file is hereby placed into the public domain.
import os,sys,re
_antlr_compiled_re = re.compile(r'// \$ANTLR.*:.*->.*\$$')
def clean_antlr_generated(basedir):
for (dpath,subdirs,fnames) in os.walk(basedir):
for fname in fnames:
fpath = os.path.join(dpath, fname)
f = open(fpath)
first = f.readline()
f.close()
if _antlr_compiled_re.match(first):
print "Deleting antlr-compiled %s" % (fpath,)
os.unlink(fpath)
if __name__ == '__main__':
basedir = sys.argv[1]
clean_antlr_generated(basedir)