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 Word, alphas, alphanums, Combine, oneOf, Optional, delimitedList, Group, Keyword
10
11testdata = """
12  int func1(float *vec, int len, double arg1);
13  int func2(float **arr, float *vec, int len, double arg1, double arg2);
14  """
15
16ident = Word(alphas, alphanums + "_")
17vartype = Combine( oneOf("float double int char") + Optional(Word("*")), adjacent = False)
18arglist = delimitedList(Group(vartype("type") + ident("name")))
19
20functionCall = Keyword("int") + ident("name") + "(" + arglist("args") + ")" + ";"
21
22for fn,s,e in functionCall.scanString(testdata):
23    print(fn.name)
24    for a in fn.args:
25        print(" - %(name)s (%(type)s)" % a)
26