Skip to content

Instantly share code, notes, and snippets.

@selimb
Last active May 13, 2016 01:26
Show Gist options
  • Save selimb/4436d5f5db94ede7cc490ff63cc31b94 to your computer and use it in GitHub Desktop.
Save selimb/4436d5f5db94ede7cc490ff63cc31b94 to your computer and use it in GitHub Desktop.
import os.path
import re
import sys
FILES = ['Date.cpp']
function_dicts = {}
def pluck_classname(filepath):
filename = os.path.basename(filepath)
classname = filename.split('.')[0]
return classname
def split_functions(lines, classname):
s = ''
functions = {}
found_func = False
pattern = r'%s::(.*?)\(' % classname
print pattern
for line in lines:
if found_func:
if line.startswith('}'):
s += line
functions[func_name] = s
s = ''
found_func = False
else:
s += line
continue
r = re.search(pattern, line)
if r is None:
continue
func_name = r.groups()[0].strip()
found_func = True
s += line
return functions
def init():
for f in FILES:
lines = open(f).readlines()
classname = pluck_classname(f)
functions = split_functions(lines, classname)
function_dicts[classname] = functions
print functions.keys()
def print_function(func_name):
for classname, functions in function_dicts.iteritems():
try:
print functions[func_name]
except KeyError:
print 'ERROR: %s not in %s' % (func_name, classname)
print
print
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment