1# 2# cLibHeader.py 3# 4# A simple parser to extract API doc info from a C header file 5# 6# Copyright, 2012 - Paul McGuire 7# 8 9from pyparsing import ( 10 Word, 11 alphas, 12 alphanums, 13 Combine, 14 oneOf, 15 Optional, 16 delimitedList, 17 Group, 18 Keyword, 19) 20 21testdata = """ 22 int func1(float *vec, int len, double arg1); 23 int func2(float **arr, float *vec, int len, double arg1, double arg2); 24 """ 25 26ident = Word(alphas, alphanums + "_") 27vartype = Combine(oneOf("float double int char") + Optional(Word("*")), adjacent=False) 28arglist = delimitedList(Group(vartype("type") + ident("name"))) 29 30functionCall = Keyword("int") + ident("name") + "(" + arglist("args") + ")" + ";" 31 32for fn, s, e in functionCall.scanString(testdata): 33 print(fn.name) 34 for a in fn.args: 35 print(" - %(name)s (%(type)s)" % a) 36