5 FUNC_SKEL = """#contributor : Andrew Gwozdziewycz <web@apgwoz.com>
6 #name : %(func_name)s(%(func_sig)s)
8 %(func_name)s(%(func_args)s)$0"""
10 func_args_re = re.compile('([a-zA-Z0-9_]+) \((.*?)\)')
12 def split_func_args(file):
14 lines = [x for x in fi.xreadlines() if not x.startswith(' ')]
17 it = func_args_re.search(n)
20 fargs.append(it.groups())
24 args = args.split('[')
25 argsl = args[0].split(',')
31 argsout.append(pieces[1])
32 if len(args) > 1 and len(args[1]):
33 newa = '[' + args[1].rstrip()
34 if not newa.endswith(']'):
42 def parse_definitions(file):
43 functions = split_func_args(file)
46 args = parse_args(f[1])
47 out.append((f[0], args))
50 def generate_snippets(outpath, defs):
52 ellipsis = ', '.join(['...'] * len(d[1]))
53 args = ', '.join(['${%s}' % x for x in d[1]])
54 filename = d[0].replace('_', '.', 1).replace('_', '-')
55 f = open(outpath + '/' + filename, 'w')
56 f.write(FUNC_SKEL % {'func_sig': ellipsis,
60 if __name__ == "__main__":
61 defs = parse_definitions("php-functions-with-args.txt")
62 generate_snippets('php-mode', defs)