beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / docs / zzipdoc / functionheader.py
blob81bb385c408aa1b814075407283acb4a29ccc023
1 from match import Match
3 class FunctionHeader:
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
9 self.comment = comment
10 self.prototype = prototype
11 self.firstline = None
12 self.otherlines = None
13 self.titleline = None
14 self.alsolist = []
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")
20 if x > 0:
21 self.firstline = self.comment[:x]
22 self.otherlines = self.comment[x:]
23 elif x == 0:
24 self.firstline = "..."
25 self.otherlines = self.comment[1:x]
26 else:
27 self.firstline = self.comment
28 self.otherlines = ""
29 return True
30 def get_firstline(self):
31 if self.firstline is None:
32 if not self.parse_firstline(): return ""
33 return self.firstline
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
42 self.titleline = line
43 self.alsolist = []
44 x = line.find("also:")
45 if x > 0:
46 self.titleline = line[:x]
47 for also in line[x+5:].split(","):
48 self.alsolist += [ also.strip() ]
49 self._alsolist = self.alsolist
50 return True
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
55 return self.alsolist
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
60 return self.titleline
61 def get_title(self):
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 ""
66 return titleline
67 def get_prototype(self):
68 return self.prototype
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:
81 return False
82 text = self.textfile.get_src_text()
83 m = Match(r"(?s)\/\*[*]+(?=\s)"
84 r"((?:.(?!\*\/))*.)\*\/"
85 r"([^/\{\}\;\#]+)[\{\;]")
86 self.children = []
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 []
96 return self.children