1 from match
import Match
4 """ parsing the comment block that is usually presented before
5 a function prototype - the prototype part is passed along
6 for further parsing through => FunctionPrototype """
7 def __init__(self
, functionheaderlist
, comment
, prototype
):
8 self
.parent
= functionheaderlist
10 self
.prototype
= prototype
12 self
.otherlines
= None
15 def get_filename(self
):
16 return self
.parent
.get_filename()
17 def parse_firstline(self
):
18 if not self
.comment
: return False
19 x
= self
.comment
.find("\n")
21 self
.firstline
= self
.comment
[:x
]
22 self
.otherlines
= self
.comment
[x
:]
24 self
.firstline
= "..."
25 self
.otherlines
= self
.comment
[1:x
]
27 self
.firstline
= self
.comment
30 def get_firstline(self
):
31 if self
.firstline
is None:
32 if not self
.parse_firstline(): return ""
34 def get_otherlines(self
):
35 if self
.firstline
is None:
36 if not self
.parse_firstline(): return ""
37 return self
.otherlines
38 def parse_titleline(self
):
39 """ split extra-notes from the firstline - keep only titleline """
40 line
= self
.get_firstline()
41 if line
is None: return False
44 x
= line
.find("also:")
46 self
.titleline
= line
[:x
]
47 for also
in line
[x
+5:].split(","):
48 self
.alsolist
+= [ also
.strip() ]
49 self
._alsolist
= self
.alsolist
51 def get_alsolist(self
):
52 """ gets the see-also notes from the firstline """
53 if self
.titleline
is None:
54 if not self
.parse_titleline(): return None
56 def get_titleline(self
):
57 """ gets firstline with see-also notes removed """
58 if self
.titleline
is None:
59 if not self
.parse_titleline(): return False
62 """ gets titleline unless that is a redirect """
63 titleline
= self
.get_titleline()
64 if titleline
& Match(r
"^\s*=>"): return ""
65 if titleline
& Match(r
"^\s*<link>"): return ""
67 def get_prototype(self
):
70 class FunctionHeaderList
:
71 """ scan for comment blocks in the source file that are followed by
72 something quite like a C definition (probably a function definition).
73 Unpack the occurrences and fill self.comment and self.prototype. """
74 def __init__(self
, textfile
= None):
75 self
.textfile
= textfile
# TextFile
76 self
.children
= None # src'style
77 def parse(self
, textfile
= None):
78 if textfile
is not None:
79 self
.textfile
= textfile
80 if self
.textfile
is None:
82 text
= self
.textfile
.get_src_text()
83 m
= Match(r
"(?s)\/\*[*]+(?=\s)"
84 r
"((?:.(?!\*\/))*.)\*\/"
85 r
"([^/\{\}\;\#]+)[\{\;]")
87 for found
in m
.finditer(text
):
88 child
= FunctionHeader(self
, found
.group(1), found
.group(2))
89 self
.children
+= [ child
]
90 return len(self
.children
) > 0
91 def get_filename(self
):
92 return self
.textfile
.get_filename()
93 def get_children(self
):
94 if self
.children
is None:
95 if not self
.parse(): return []