1
from match import Match
3
class FunctionPrototype:
4
""" takes a single function prototype line (cut from some source file)
5
and parses it into the relevant portions 'prespec', 'namespec' and
6
'callspec'. Additionally we present 'name' from the namespec that is
7
usually used as the filename stem for a manual page """
8
def __init__(self, functionheader = None):
9
self.functionheader = functionheader
14
def get_functionheader(self):
15
return self.functionheader
16
def get_prototype(self):
17
if self.functionheader is None:
19
return self.functionheader.get_prototype()
20
def get_filename(self):
21
if self.functionheader is None:
23
return self.functionheader.get_filename()
24
def parse(self, functionheader = None):
25
if functionheader is not None:
26
self.functionheader = functionheader
27
if self.functionheader is None:
30
prototype = self.get_prototype()
31
if prototype & found(r"(?s)^(.*[^.])"
34
self.prespec = found.group(1).lstrip()
35
self.namespec = found.group(2)
36
self.callspec = found.group(3).lstrip()
37
self.name = self.namespec.strip()
40
def _assert_parsed(self):
44
def get_prespec(self):
45
if not self._assert_parsed(): return None
47
def get_namespec(self):
48
if not self._assert_parsed(): return None
50
def get_callspec(self):
51
if not self._assert_parsed(): return None
54
if not self._assert_parsed(): return None
57
if not self.namespec: return self.namespec
58
return ("<fu:protospec><fu:prespec>"+self.prespec+"</fu:prespec>"+
59
"<fu:namespec>"+self.namespec+"</fu:namespec>"+
60
"<fu:callspec>"+self.callspec+"</fu:callspec></fu:protospec>")