[mlpack-git] master: First round of doxygen post-processing. (5278e8f)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Tue Aug 25 17:32:36 EDT 2015


Repository : https://github.com/mlpack/mlpack.org

On branch  : master
Link       : https://github.com/mlpack/mlpack.org/compare/f99b1aa56de0b33a52827556b4135ccabd1da5fb...5278e8fd3c5436ace56cd787823ddab483d0bfb3

>---------------------------------------------------------------

commit 5278e8fd3c5436ace56cd787823ddab483d0bfb3
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Aug 25 17:32:17 2015 -0400

    First round of doxygen post-processing.


>---------------------------------------------------------------

5278e8fd3c5436ace56cd787823ddab483d0bfb3
 docs/doxygen-post/html_template_labeler.py   | 51 ++++++++++++++++++++
 docs/doxygen-post/label_html_templates.py    | 10 ++++
 docs/doxygen-post/template_annotator.py      | 70 ++++++++++++++++++++++++++++
 docs/doxygen-post/test_template_annotator.py | 37 +++++++++++++++
 4 files changed, 168 insertions(+)

diff --git a/docs/doxygen-post/html_template_labeler.py b/docs/doxygen-post/html_template_labeler.py
new file mode 100644
index 0000000..616e549
--- /dev/null
+++ b/docs/doxygen-post/html_template_labeler.py
@@ -0,0 +1,51 @@
+from HTMLParser import HTMLParser
+from template_annotator import TemplateAnnotator
+import sys
+
+class HTMLTemplateLabeler(HTMLParser):
+  current_data = ''
+
+  def handle_starttag(self, tag, attrs):
+    # Print the tag.  Is it a br?  Then we can ignore it.
+    if tag == "br":
+      print("<br />")
+      return
+
+    # Process the current data we have.
+    if self.current_data != '':
+      self.process_data()
+
+    print("<" + tag + " " + ' '.join([a[0] + '="' + a[1] + '"' for a in attrs]) + ">")
+    self.current_data = ''
+
+  def handle_endtag(self, tag):
+    # Print the tag, after processing the data we currently have.
+    self.process_data()
+
+    # Print the closing tag.
+    print ("</" + tag + ">")
+    self.current_data = ''
+
+  # HTMLParser splits up the escaped HTML characters, so we have to reassemble
+  # by having an internal data storage buffer.
+  def handle_data(self, data):
+    self.current_data = self.current_data + data
+
+  def handle_entityref(self, name):
+    self.current_data = self.current_data + "&" + name + ";"
+
+  def handle_charref(self, name):
+    self.current_data = self.current_data + "&#" + name + ";"
+
+  def process_data(self):
+    # Do nothing with empty data.
+    if self.current_data == '':
+      return
+
+    # See if it matches the template grammar.
+    t = TemplateAnnotator()
+    processed = t.process(self.current_data) # Will modify, if it matches.
+
+    # Print the data.
+    print(processed)
+
diff --git a/docs/doxygen-post/label_html_templates.py b/docs/doxygen-post/label_html_templates.py
new file mode 100755
index 0000000..0f91878
--- /dev/null
+++ b/docs/doxygen-post/label_html_templates.py
@@ -0,0 +1,10 @@
+#!/usr/bin/python
+#
+# Process the given HTML file, outputting the labeled templates on stdout.
+import sys
+from html_template_labeler import HTMLTemplateLabeler
+
+labeler = HTMLTemplateLabeler()
+
+f = open(sys.argv[1], 'r')
+labeler.feed(f.read())
diff --git a/docs/doxygen-post/template_annotator.py b/docs/doxygen-post/template_annotator.py
new file mode 100644
index 0000000..e73d692
--- /dev/null
+++ b/docs/doxygen-post/template_annotator.py
@@ -0,0 +1,70 @@
+from pyparsing import Literal, Word, Combine, Group, Optional, ZeroOrMore, \
+    Forward, nums, alphas, alphanums, LineEnd, ParseException, Suppress, \
+    OneOrMore, delimitedList
+
+class TemplateAnnotator:
+
+  def __init__(self):
+
+    # Define the grammar.  We need some literals.
+    templateLiteral = Literal("template")("template")
+    openBracket = Literal("&lt;")("open_bracket")
+    closeBracket = Literal("&gt;")("close_bracket")
+    typenameLiteral = Literal("typename")("type_decl")
+    classLiteral = Literal("class")("type_decl")
+    equalLiteral = Literal("=")
+    comma = Literal(",")
+    ellipses = Literal("...")
+    operatorLiteral = Literal("operator")
+    tildeLiteral = Literal("~")
+
+    digit = Word(nums)
+
+    identifier_nondigit = Word(alphas + "_:") # catch underscores and ::
+
+    identifier = Forward()
+    identifier << (identifier_nondigit + Optional(identifier) + Optional(digit))("identifier*")
+
+    default_argument = Group(Literal("=")("equals") + identifier)("default_argument*")
+
+    template_param_list = Forward()
+
+    template_param = Group((classLiteral + Optional(identifier) + Optional(default_argument)) |\
+                           (typenameLiteral + Optional(identifier) + Optional(default_argument)) |\
+                           (templateLiteral + openBracket + template_param_list + closeBracket + classLiteral + Optional(identifier) + Optional(default_argument)))("template_param*")
+
+    template_param_list << Group(delimitedList(template_param))("template_param_list")
+
+    self.grammar = (Literal("template")("template_decl") + openBracket + template_param_list + closeBracket) |\
+                   (Literal("template")("template_decl") + openBracket + closeBracket)
+
+  def process(self, string):
+    try:
+      a = self.grammar.parseString(string)
+
+      # Now process the string.  We get XML back, but we really need named divs.
+      return a.asXML('template_expr')\
+          .replace('<template_expr', '<div class="template_expr"')\
+          .replace('</template_expr', '</div')\
+          .replace('<template_decl', '<div class="template_decl"')\
+          .replace('</template_decl', '</div')\
+          .replace('<open_bracket', '<div class="open_bracket"')\
+          .replace('</open_bracket', '</div')\
+          .replace('&amp;lt;', '&lt;')\
+          .replace('<close_bracket', '<div class="close_bracket"')\
+          .replace('</close_bracket', '</div')\
+          .replace('&amp;gt;', '&gt;')\
+          .replace('<template_param_list', '<div class="template_param_list"')\
+          .replace('</template_param_list', '</div')\
+          .replace('<template_param', '<div class="template_param"')\
+          .replace('</template_param', '</div')\
+          .replace('<type_decl', '<div class="type_decl"')\
+          .replace('</type_decl', '</div')\
+          .replace('<identifier', '<div class="identifier"')\
+          .replace('</identifier', '</div')\
+
+    except ParseException, err:
+#      print err.line
+#      print " "*(err.column - 1) + "^"
+#      print err
+      return string # Unmodified.
diff --git a/docs/doxygen-post/test_template_annotator.py b/docs/doxygen-post/test_template_annotator.py
new file mode 100755
index 0000000..5953448
--- /dev/null
+++ b/docs/doxygen-post/test_template_annotator.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+from template_annotator import TemplateAnnotator
+t = TemplateAnnotator()
+a = t.grammar.parseString('template &lt; typename A &gt;')
+
+print a.asXML('div')
+print ''
+
+a = t.grammar.parseString('template &lt; &gt;')
+
+print a.asXML('div')
+print ''
+
+a = t.grammar.parseString('template &lt; typename A, typename B &gt;')
+
+print a.asXML('div')
+print ''
+
+a = t.grammar.parseString('template&lt;typename A&gt;')
+
+print a.asXML('div')
+print ''
+
+a = t.grammar.parseString("template&lt;typename VecType &gt;")
+
+print a.asXML('div')
+print ''
+
+a = t.grammar.parseString("template&lt;typename MetricType, typename StatisticType = EmptyStatistic, typename MatType = arma::mat &gt;")
+
+print a.asXML('div')
+print ''
+
+a = t.grammar.parseString('template &lt; template &lt; typename A &gt; class B &gt;')
+
+print a.asXML('div')
+print ''



More information about the mlpack-git mailing list