From: <gr...@us...> - 2003-04-20 16:45:15
|
Update of /cvsroot/alleg/makedoc/python In directory sc8-pr-cvs1:/tmp/cvs-serv8966 Modified Files: decepticon.py Log Message: More extraction functions. Standard node recursion with curried ignore function. Added HTML title, function arguments and return value. Index: decepticon.py =================================================================== RCS file: /cvsroot/alleg/makedoc/python/decepticon.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- decepticon.py 17 Apr 2003 21:25:19 -0000 1.1 +++ decepticon.py 20 Apr 2003 16:45:12 -0000 1.2 @@ -25,6 +25,12 @@ def ignored(func_name, node): print "%s ignored node: %s" % (func_name, node) +class IGNORED: + def __init__(self, func_name): + self.func_name = func_name + def ignored(self, node): + ignored(self.func_name, node) + def swallow(*args): pass @@ -37,11 +43,30 @@ del node_list[f] return temp -def get_plain_text(node): - if node.nodeType == node.TEXT_NODE: - return node.data +def extract_first_node(node_name, node_list): + for node in filter_node_name(node_name, node_list, 1)[:1]: + return [node] + return [] + +def get_plain_text(node, node_name = ""): + if node_name: + if node.nodeName != node_name: + for node in node.childNodes: + res = get_plain_text(node, node_name) + if res: + return res + return "" + else: + return get_plain_text(node) else: - return "".join(map(get_plain_text, node.childNodes)) + if node.nodeType == node.TEXT_NODE: + return node.data + else: + return "".join(map(get_plain_text, node.childNodes)) + +def get_argument_data(argument_node): + return (get_plain_text(argument_node, "type"), + get_plain_text(argument_node, "name")) def process_document(root_node): children = root_node.childNodes[:] @@ -50,10 +75,13 @@ if len(titles): buf.append(get_plain_text(titles[0])) buf.append("</title>\n</head><body>\n") + buf.append("<h1>%s</h1>\n" % get_plain_text(titles[0])) + + w = IGNORED("document") + branch = {"chapter": process_chapter, "#text": swallow} for node in children: - if node.nodeName == "chapter": - process_chapter(node) + branch.get(node.nodeName, w.ignored)(node) buf.append("</body></html>\n") @@ -63,10 +91,11 @@ if len(titles): buf.extend(["<h1>", get_plain_text(titles[0]), "</h1>\n"]) + w = IGNORED("chapter") branch = {"api-section": process_api_section, "#text": swallow} for node in children: - branch.get(node.nodeName, lambda x: ignored("chapter", x))(node) + branch.get(node.nodeName, w.ignored)(node) def process_api_section(api_node): children = api_node.childNodes[:] @@ -74,11 +103,12 @@ if len(titles): buf.extend(["<h2>", get_plain_text(titles[0]), "</h2>\n"]) + w = IGNORED("api-section") branch = {"function": process_function, "variable": process_variable, "typedef": process_typedef, "#text": swallow} for node in children: - branch.get(node.nodeName, lambda x: ignored("api-section", x))(node) + branch.get(node.nodeName, w.ignored)(node) def process_function(function_node): children = function_node.childNodes[:] @@ -87,10 +117,32 @@ assert name name = get_plain_text(name[0]) - buf.extend(["<b>Function: ", name, "</b><br>\n"]) + buf.extend(["<b>Function: </b>", name]) + return_value_node = extract_first_node("return-value", children) + cross_refs_node = extract_first_node("cross-refs", children) + + started_arguments = 0 + for arguments in extract_first_node("argument-list", children): + for argument in filter_node_name("argument", arguments.childNodes, 1): + type, name = get_argument_data(argument) + if started_arguments: + buf.append(", %s <b>%s</b>" % (type, name)) + else: + buf.append("(%s <b>%s</b>" % (type, name)) + started_arguments = 1 + if started_arguments: + buf.append(")") + buf.append("</b>\n"); + + w = IGNORED("function") + branch = {"#text": swallow} for node in children: - ignored("function", node.nodeName) + branch.get(node.nodeName, w.ignored)(node) + + if return_value_node: + buf.extend(["<blockquote>\n<b>Return value:</b> ", + get_plain_text(return_value_node[0]), "</blockquote>\n"]) def process_variable(variable_node): children = variable_node.childNodes[:] |