def html_footer(self): navi = self.navigation() if not navi: return "</body></html>" else: return navi & (Match(r"(?m)(.*</body></html>)") >> "%&%&%&%\\1") & (Match(r"(?s).*%&%&%&%") >> "")
def resolve_links(self, text): text &= (Match("(?s)<link>([^<>]*)(\(\d\))</link>") >> (lambda x: self.resolve_external(x.group(1), x.group(2)))) text &= (Match("(?s)<link>(\w+)</link>") >> (lambda x: self.resolve_internal(x.group(1)))) if len(self.not_found_in_anchors): print("not found in anchors: {}".format(self.not_found_in_anchors)) return (text & Match("(?s)<link>([^<>]*)</link>") >> "<code>\\1</code>")
def markup_link_syntax(text): """ markup the link-syntax ` => somewhere ` in the text block """ return (text & Match(r"(?m)(^|\s)\=\>\"([^\"]*)\"") >> r"\1<link>\2</link>" & Match(r"(?m)(^|\s)\=\>\'([^\']*)\'") >> r"\1<link>\2</link>" & Match(r"(?m)(^|\s)\=\>\s(\w[\w.]*\w\(\d+\))") >> r"\1<link>\2</link>" & Match(r"(?m)(^|\s)\=\>\s([^\s\,\.\!\?]+)") >> r"\1<link>\2</link>")
def parse(self, textfile = None): if textfile is not None: self.textfile = textfile if self.textfile is None: return False text = self.textfile.get_src_text() m = Match(r"(?s)\/\*[*]+(?=\s)" r"((?:.(?!\*\/))*.)\*\/" r"([^/\{\}\;\#]+)[\{\;]") self.children = [] for found in m.finditer(text): child = FunctionHeader(self, found.group(1), found.group(2)) self.children += [ child ] return len(self.children) > 0
def parse(self, functionheader=None): if functionheader is not None: self.functionheader = functionheader if self.functionheader is None: return False found = Match() prototype = self.get_prototype() if prototype & found(r"(?s)^(.*[^.])" r"\b(\w[\w.]*\w)\b" r"(\s*\(.*)$"): self.prespec = found.group(1).lstrip() self.namespec = found.group(2) self.callspec = found.group(3).lstrip() self.name = self.namespec.strip() return True return False
def html_header(self): navi = self.navigation() if not navi: T = "<html><head>" title = self.get_title() if title: T += "<title>" + title + "</title>" T += "\n" for style in self.style: T += self._html_style(style) T += "\n" return T + "</head><body>" else: title = self.get_title() return navi & (Match(r"<!--title-->") >> " - " + title) & ( Match(r"<!--VERSION-->") >> self.o.version) & ( Match(r"(?m).*</body></html>") >> "")
def paramdef2html(self, text): s = Match() txt = text & s(r"\s+<paramdef>") >> r"\n<nobr>" txt &= s(r"<paramdef>") >> r"<nobr>" txt &= s(r"</paramdef>") >> r"</nobr>" txt &= s(r"<parameters>") >> r"\n <code>" txt &= s(r"</parameters>") >> r"</code>\n" return txt
def _filename(self, filename): if filename is not None: self.filename = filename filename = self.filename if not filename & Match(r"\.\w+$"): ext = self.o.html if not ext: ext = "html" filename += "." + ext return filename
def here(text): has_function = Match("<function>(\w*)</function>") if text & has_function: func = has_function[1] self.anchors += [func] return (text & has_function >> '<a name="' + "\\1" + '">' + "\\1" + '</a>') else: return text
def resolve_external(self, func, sect): x = Match() if func & x("^zlib(.*)"): return ('<a href="' + self.http_zlib + x[1] + '">' + "<code>" + func + sect + "</code>" + '</a>') if sect & x("[23]"): return ('<a href="' + self.http_opengroup + func + '.html">' + "<code>" + func + sect + "</code>" + '</a>') return "<code>" + func + "<em>" + sect + "</em></sect>"
def scan(self, optionstring): # option-name or None x = Match() if optionstring & x(r"^--?(\w+)=(.*)"): self.var[x[1]] = x[2] return x[1] if optionstring & x(r"^--?no-(\w+)$"): self.var[x[1]] = "" return x[1] if optionstring & x(r"^--?(\w+)$"): self.var[x[1]] = "*" return x[1] return None
def parse(self, textfile=None): if textfile is not None: self.textfile = textfile if self.textfile is None: return False x = Match() text = self.textfile.get_src_text() if not text: print("nonexistent file: " + self.textfile.get_filename()) return False if text & x(r"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/" r"(?:\s*\#(?:define|ifdef|endif)[ ]*\S*[ ]*\S*)*" r"(\s*\#include\s*<[^<>]*>(?:\s*//[^\n]*)?)"): self.comment = x[1] self.mainheader = x[2].strip() elif text & x(r"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/"): self.comment = x[1] elif text & x(r"(?s)(?:\s*\#(?:define|ifdef|endif)[ ]*\S*[ ]*\S*)*" r"(\s*\#include\s*<[^<>]*>(?:\s*//[^\n]*)?)"): self.mainheader = x[1].strip() return True
def parse(self, header = None): if header is not None: self.header = header if self.header is None: return False comment = self.header.comment try: comment = self.header.get_otherlines() except Exception as e: pass mode = "" text = "" for line in comment.split("\n"): check = Match() if line & check(r"^\s?\s?\s?[*]\s+[*]\s(.*)"): if mode != "ul": if mode: text += "</"+mode+">" mode = "ul" ; text += "<"+mode+">" line = check.group(1) text += "<li><p> "+self.markup_para_line(line)+" </p></li>\n" elif line & check(r"^\s?\s?\s?[*](.*)"): if mode != "para": if mode: text += "</"+mode+">" mode = "para" ; text += "<"+mode+">" line = check.group(1) if line.strip() == "": text += "</para><para>"+"\n" else: text += " "+self.markup_para_line(line)+"\n" else: if mode != "screen": if mode: text += "</"+mode+">" mode = "screen" ; text += "<"+mode+">" text += " "+self.markup_screen_line(line)+"\n" if mode: text += "</"+mode+">"+"\n" self.text = (text & Match(r"(<para>)(\s*[R]eturns)") >>r"\1This function\2" & Match(r"(?s)<para>\s*</para><para>") >> "<para>" & Match(r"(?s)<screen>\s*</screen>") >> "") return True
def get_title(self): """ gets titleline unless that is a redirect """ titleline = self.get_titleline() if titleline & Match(r"^\s*=>"): return "" if titleline & Match(r"^\s*<link>"): return "" return titleline
def _fetch_rootnode(self, text): fetch = Match(r"^[^<>]*<(\w+)\b") if text & fetch: return fetch[1] return self.rootnode
def link(text): return (text & Match("<function>(\w*)</function>") >> "<link>\\1</link>")