Improved javadoc comments generation scripts; fixed some typos in documentation
This commit is contained in:
@@ -218,7 +218,7 @@ Closes video file or capturing device.
|
|||||||
|
|
||||||
.. ocv:pyfunction:: cv2.VideoCapture.release()
|
.. ocv:pyfunction:: cv2.VideoCapture.release()
|
||||||
|
|
||||||
.. ocv:cfunction: void cvReleaseCapture(CvCapture** capture)
|
.. ocv:cfunction:: void cvReleaseCapture(CvCapture** capture)
|
||||||
|
|
||||||
The methods are automatically called by subsequent :ocv:func:`VideoCapture::open` and by ``VideoCapture`` destructor.
|
The methods are automatically called by subsequent :ocv:func:`VideoCapture::open` and by ``VideoCapture`` destructor.
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ Grabs the next frame from video file or capturing device.
|
|||||||
|
|
||||||
.. ocv:pyfunction:: cv2.VideoCapture.grab() -> successFlag
|
.. ocv:pyfunction:: cv2.VideoCapture.grab() -> successFlag
|
||||||
|
|
||||||
.. ocv:cfunction: int cvGrabFrame(CvCapture* capture)
|
.. ocv:cfunction:: int cvGrabFrame(CvCapture* capture)
|
||||||
|
|
||||||
.. ocv:pyoldfunction:: cv.GrabFrame(capture) -> int
|
.. ocv:pyoldfunction:: cv.GrabFrame(capture) -> int
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ Decodes and returns the grabbed video frame.
|
|||||||
|
|
||||||
.. ocv:pyfunction:: cv2.VideoCapture.retrieve([image[, channel]]) -> successFlag, image
|
.. ocv:pyfunction:: cv2.VideoCapture.retrieve([image[, channel]]) -> successFlag, image
|
||||||
|
|
||||||
.. ocv:cfunction: IplImage* cvRetrieveFrame(CvCapture* capture)
|
.. ocv:cfunction:: IplImage* cvRetrieveFrame(CvCapture* capture)
|
||||||
|
|
||||||
.. ocv:pyoldfunction:: cv.RetrieveFrame(capture) -> iplimage
|
.. ocv:pyoldfunction:: cv.RetrieveFrame(capture) -> iplimage
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ Grabs, decodes and returns the next video frame.
|
|||||||
|
|
||||||
.. ocv:pyfunction:: cv2.VideoCapture.read([image]) -> successFlag, image
|
.. ocv:pyfunction:: cv2.VideoCapture.read([image]) -> successFlag, image
|
||||||
|
|
||||||
.. ocv:cfunction: IplImage* cvQueryFrame(CvCapture* capture)
|
.. ocv:cfunction:: IplImage* cvQueryFrame(CvCapture* capture)
|
||||||
|
|
||||||
.. ocv:pyoldfunction:: cv.QueryFrame(capture) -> iplimage
|
.. ocv:pyoldfunction:: cv.QueryFrame(capture) -> iplimage
|
||||||
|
|
||||||
@@ -444,7 +444,7 @@ VideoWriter::open
|
|||||||
-----------------
|
-----------------
|
||||||
Initializes or reinitializes video writer.
|
Initializes or reinitializes video writer.
|
||||||
|
|
||||||
.. ocv:function: bool VideoWriter::open(const string& filename, int fourcc, double fps, Size frameSize, bool isColor=true)
|
.. ocv:function:: bool VideoWriter::open(const string& filename, int fourcc, double fps, Size frameSize, bool isColor=true)
|
||||||
|
|
||||||
.. ocv:pyfunction:: cv2.VideoWriter.open(filename, fourcc, fps, frameSize[, isColor]) -> retval
|
.. ocv:pyfunction:: cv2.VideoWriter.open(filename, fourcc, fps, frameSize[, isColor]) -> retval
|
||||||
|
|
||||||
@@ -455,7 +455,7 @@ VideoWriter::isOpened
|
|||||||
---------------------
|
---------------------
|
||||||
Returns true if video writer has been successfully initialized.
|
Returns true if video writer has been successfully initialized.
|
||||||
|
|
||||||
.. ocv:function: bool VideoWriter::isOpened()
|
.. ocv:function:: bool VideoWriter::isOpened()
|
||||||
|
|
||||||
.. ocv:pyfunction:: cv2.VideoWriter.isOpened() -> retval
|
.. ocv:pyfunction:: cv2.VideoWriter.isOpened() -> retval
|
||||||
|
|
||||||
|
@@ -1537,7 +1537,7 @@ The second case corresponds to a kernel of:
|
|||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
:ocv:func:`Scharr`,
|
:ocv:func:`Scharr`,
|
||||||
:ocv:func:`Lapacian`,
|
:ocv:func:`Laplacian`,
|
||||||
:ocv:func:`sepFilter2D`,
|
:ocv:func:`sepFilter2D`,
|
||||||
:ocv:func:`filter2D`,
|
:ocv:func:`filter2D`,
|
||||||
:ocv:func:`GaussianBlur`
|
:ocv:func:`GaussianBlur`
|
||||||
|
@@ -23,7 +23,7 @@ def document(infile, outfile, decls):
|
|||||||
marker = parceJavadocMarker(l)
|
marker = parceJavadocMarker(l)
|
||||||
decl = decls.get(marker[0],None)
|
decl = decls.get(marker[0],None)
|
||||||
if decl:
|
if decl:
|
||||||
for line in makeJavadoc(decl, marker[2]).split("\n"):
|
for line in makeJavadoc(decl, decls, marker[2]).split("\n"):
|
||||||
outf.write(marker[1] + line + "\n")
|
outf.write(marker[1] + line + "\n")
|
||||||
else:
|
else:
|
||||||
print "Error: could not find documentation for %s" % l.lstrip()[len(javadoc_marker):-1]
|
print "Error: could not find documentation for %s" % l.lstrip()[len(javadoc_marker):-1]
|
||||||
@@ -50,12 +50,12 @@ def ReformatForJavadoc(s):
|
|||||||
pos_end = min(77, len(term)-1)
|
pos_end = min(77, len(term)-1)
|
||||||
while pos_start < pos_end:
|
while pos_start < pos_end:
|
||||||
if pos_end - pos_start == 77:
|
if pos_end - pos_start == 77:
|
||||||
while pos_end >= pos_start:
|
while pos_end >= pos_start+60:
|
||||||
if not term[pos_end].isspace():
|
if not term[pos_end].isspace():
|
||||||
pos_end -= 1
|
pos_end -= 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if pos_end < pos_start:
|
if pos_end < pos_start+60:
|
||||||
pos_end = min(pos_start + 77, len(term)-1)
|
pos_end = min(pos_start + 77, len(term)-1)
|
||||||
while pos_end < len(term):
|
while pos_end < len(term):
|
||||||
if not term[pos_end].isspace():
|
if not term[pos_end].isspace():
|
||||||
@@ -72,6 +72,8 @@ def getJavaName(decl):
|
|||||||
name += decl["module"]
|
name += decl["module"]
|
||||||
if "class" in decl:
|
if "class" in decl:
|
||||||
name += "." + decl["class"]
|
name += "." + decl["class"]
|
||||||
|
else:
|
||||||
|
name += "." + decl["module"].capitalize()
|
||||||
if "method" in decl:
|
if "method" in decl:
|
||||||
name += "." + decl["method"]
|
name += "." + decl["method"]
|
||||||
return name
|
return name
|
||||||
@@ -84,7 +86,7 @@ def getDocURL(decl):
|
|||||||
url += "#" + decl["name"].replace("::","-").replace("()","").replace("=","").strip().rstrip("_").replace(" ","-").replace("_","-").lower()
|
url += "#" + decl["name"].replace("::","-").replace("()","").replace("=","").strip().rstrip("_").replace(" ","-").replace("_","-").lower()
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def makeJavadoc(decl, args = None):
|
def makeJavadoc(decl, decls, args = None):
|
||||||
doc = ""
|
doc = ""
|
||||||
prefix = "/**\n"
|
prefix = "/**\n"
|
||||||
|
|
||||||
@@ -130,7 +132,11 @@ def makeJavadoc(decl, args = None):
|
|||||||
# other links
|
# other links
|
||||||
if "seealso" in decl:
|
if "seealso" in decl:
|
||||||
for see in decl["seealso"]:
|
for see in decl["seealso"]:
|
||||||
doc += prefix + " * @see " + see.replace("::",".") + "\n"
|
seedecl = decls.get(see,None)
|
||||||
|
if seedecl:
|
||||||
|
doc += prefix + " * @see " + getJavaName(seedecl) + "\n"
|
||||||
|
else:
|
||||||
|
doc += prefix + " * @see " + see.replace("::",".") + "\n"
|
||||||
prefix = " *\n"
|
prefix = " *\n"
|
||||||
|
|
||||||
#doc += prefix + " * File: " + decl["file"] + " (line " + str(decl["line"]) + ")\n"
|
#doc += prefix + " * File: " + decl["file"] + " (line " + str(decl["line"]) + ")\n"
|
||||||
@@ -155,9 +161,11 @@ if __name__ == "__main__":
|
|||||||
print "Parsing documentation..."
|
print "Parsing documentation..."
|
||||||
for m in ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts"]:
|
for m in ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts"]:
|
||||||
parser.parse(m, os.path.join(selfpath, "../" + m))
|
parser.parse(m, os.path.join(selfpath, "../" + m))
|
||||||
|
|
||||||
|
parser.printSummary()
|
||||||
|
|
||||||
for i in range(1, len(sys.argv)):
|
for i in range(1, len(sys.argv)):
|
||||||
folder = os.path.abspath(sys.argv[i])
|
folder = os.path.abspath(sys.argv[i])
|
||||||
for jfile in glob.glob(os.path.join(folder,"*.java")):
|
for jfile in [f for f in glob.glob(os.path.join(folder,"*.java")) if not f.endswith("-jdoc.java")]:
|
||||||
outfile = os.path.abspath(os.path.basename(jfile).replace(".java", "-jdoc.java"))
|
outfile = os.path.abspath(os.path.basename(jfile).replace(".java", "-jdoc.java"))
|
||||||
document(jfile, outfile, parser.definitions)
|
document(jfile, outfile, parser.definitions)
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
import os, sys, re, string, glob
|
import os, sys, re, string, glob
|
||||||
|
verbose = False
|
||||||
|
show_warnings = True
|
||||||
|
show_errors = True
|
||||||
|
|
||||||
class DeclarationParser(object):
|
class DeclarationParser(object):
|
||||||
def __init__(self, line=None):
|
def __init__(self, line=None):
|
||||||
@@ -86,14 +89,16 @@ class RstParser(object):
|
|||||||
try:
|
try:
|
||||||
self.parse_section(module_name, section_name, file_name, lineno, lines)
|
self.parse_section(module_name, section_name, file_name, lineno, lines)
|
||||||
except AssertionError, args:
|
except AssertionError, args:
|
||||||
print "RST parser error: assertion in \"%s\" File: %s (line %s)" % (section_name, file_name, lineno)
|
if show_errors:
|
||||||
print " Details: %s" % args
|
print >> sys.stderr, "RST parser error: assertion in \"%s\" File: %s (line %s)" % (section_name, file_name, lineno)
|
||||||
|
print >> sys.stderr, " Details: %s" % args
|
||||||
|
|
||||||
def parse_section(self, module_name, section_name, file_name, lineno, lines):
|
def parse_section(self, module_name, section_name, file_name, lineno, lines):
|
||||||
self.sections_total += 1
|
self.sections_total += 1
|
||||||
# skip sections having whitespace in name
|
# skip sections having whitespace in name
|
||||||
if section_name.find(" ") >= 0 and section_name.find("::operator") < 0:
|
if section_name.find(" ") >= 0 and section_name.find("::operator") < 0:
|
||||||
print "SKIPPED: \"%s\" File: %s (line %s)" % (section_name, file_name, lineno)
|
if show_errors:
|
||||||
|
print "SKIPPED: \"%s\" File: %s (line %s)" % (section_name, file_name, lineno)
|
||||||
self.sections_skipped += 1
|
self.sections_skipped += 1
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -136,15 +141,6 @@ class RstParser(object):
|
|||||||
else:
|
else:
|
||||||
capturing_seealso = False
|
capturing_seealso = False
|
||||||
|
|
||||||
# continue param parsing
|
|
||||||
if pdecl.active:
|
|
||||||
pdecl.append(l)
|
|
||||||
if pdecl.active:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
self.add_new_pdecl(func, pdecl)
|
|
||||||
# do not continue - current line can contain next parameter definition
|
|
||||||
|
|
||||||
ll = l.strip()
|
ll = l.strip()
|
||||||
if ll == "..":
|
if ll == "..":
|
||||||
expected_brief = False
|
expected_brief = False
|
||||||
@@ -158,14 +154,19 @@ class RstParser(object):
|
|||||||
else:
|
else:
|
||||||
skip_code_lines = False
|
skip_code_lines = False
|
||||||
|
|
||||||
if ll.startswith(".. code-block::") or ll.startswith(".. math::") or ll.startswith(".. image::"):
|
if ll.startswith(".. code-block::") or ll.startswith(".. image::"):
|
||||||
|
#or ll.startswith(".. math::") or ll.startswith(".. image::"):
|
||||||
skip_code_lines = True
|
skip_code_lines = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# todo: parse structure members; skip them for now
|
# todo: parse structure members; skip them for now
|
||||||
if ll.startswith(".. ocv:member::"):
|
if ll.startswith(".. ocv:member::"):
|
||||||
skip_code_lines = True
|
skip_code_lines = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
#ignore references (todo: collect them)
|
||||||
|
if l.startswith(".. ["):
|
||||||
|
continue
|
||||||
|
|
||||||
if ll.startswith(".. "):
|
if ll.startswith(".. "):
|
||||||
expected_brief = False
|
expected_brief = False
|
||||||
@@ -173,6 +174,15 @@ class RstParser(object):
|
|||||||
# turn on line-skipping mode for code fragments
|
# turn on line-skipping mode for code fragments
|
||||||
skip_code_lines = True
|
skip_code_lines = True
|
||||||
ll = ll[:len(ll)-2]
|
ll = ll[:len(ll)-2]
|
||||||
|
|
||||||
|
# continue param parsing (process params after processing .. at the beginning of the line and :: at the end)
|
||||||
|
if pdecl.active:
|
||||||
|
pdecl.append(l)
|
||||||
|
if pdecl.active:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
self.add_new_pdecl(func, pdecl)
|
||||||
|
# do not continue - current line can contain next parameter definition
|
||||||
|
|
||||||
# parse ".. seealso::" blocks
|
# parse ".. seealso::" blocks
|
||||||
if ll.startswith(".. seealso::"):
|
if ll.startswith(".. seealso::"):
|
||||||
@@ -231,7 +241,9 @@ class RstParser(object):
|
|||||||
# endfor l in lines
|
# endfor l in lines
|
||||||
|
|
||||||
if fdecl.balance != 0:
|
if fdecl.balance != 0:
|
||||||
print "RST parser error: invalid parentheses balance in \"%s\" File: %s (line %s)" % (section_name, file_name, lineno)
|
if show_errors:
|
||||||
|
print >> sys.stderr, "RST parser error: invalid parentheses balance in \"%s\" File: %s (line %s)" % (section_name, file_name, lineno)
|
||||||
|
return
|
||||||
|
|
||||||
# save last parameter if needed
|
# save last parameter if needed
|
||||||
if pdecl.active:
|
if pdecl.active:
|
||||||
@@ -242,10 +254,11 @@ class RstParser(object):
|
|||||||
if self.validate(func):
|
if self.validate(func):
|
||||||
self.definitions[func["name"]] = func
|
self.definitions[func["name"]] = func
|
||||||
self.sections_parsed += 1
|
self.sections_parsed += 1
|
||||||
#self.print_info(func)
|
if verbose:
|
||||||
|
self.print_info(func)
|
||||||
elif func:
|
elif func:
|
||||||
self.print_info(func, True)
|
if show_errors:
|
||||||
pass
|
self.print_info(func, True, sys.stderr)
|
||||||
|
|
||||||
def parse_rst_file(self, module_name, doc):
|
def parse_rst_file(self, module_name, doc):
|
||||||
doc = os.path.abspath(doc)
|
doc = os.path.abspath(doc)
|
||||||
@@ -264,8 +277,8 @@ class RstParser(object):
|
|||||||
# handle tabs
|
# handle tabs
|
||||||
if l.find("\t") >= 0:
|
if l.find("\t") >= 0:
|
||||||
whitespace_warnings += 1
|
whitespace_warnings += 1
|
||||||
if whitespace_warnings <= max_whitespace_warnings:
|
if whitespace_warnings <= max_whitespace_warnings and show_warnings:
|
||||||
print "RST parser warning: tab symbol instead of space is used at file %s (line %s)" % (doc, lineno)
|
print >> sys.stderr, "RST parser warning: tab symbol instead of space is used at file %s (line %s)" % (doc, lineno)
|
||||||
l = l.replace("\t", " ")
|
l = l.replace("\t", " ")
|
||||||
|
|
||||||
# handle first line
|
# handle first line
|
||||||
@@ -311,47 +324,48 @@ class RstParser(object):
|
|||||||
def add_new_pdecl(self, func, decl):
|
def add_new_pdecl(self, func, decl):
|
||||||
params = func.get("params",{})
|
params = func.get("params",{})
|
||||||
if decl.name in params:
|
if decl.name in params:
|
||||||
print "RST parser error: redefinition of parameter \"%s\" in \"%s\" File: %s (line %s)" \
|
if show_errors:
|
||||||
% (decl.name, func["name"], func["file"], func["line"])
|
print >> sys.stderr, "RST parser error: redefinition of parameter \"%s\" in \"%s\" File: %s (line %s)" \
|
||||||
|
% (decl.name, func["name"], func["file"], func["line"])
|
||||||
else:
|
else:
|
||||||
params[decl.name] = decl.comment
|
params[decl.name] = decl.comment
|
||||||
func["params"] = params
|
func["params"] = params
|
||||||
|
|
||||||
def print_info(self, func, skipped=False):
|
def print_info(self, func, skipped=False, out = sys.stdout):
|
||||||
print
|
print >> out
|
||||||
if skipped:
|
if skipped:
|
||||||
print "SKIPPED DEFINITION:"
|
print >> out, "SKIPPED DEFINITION:"
|
||||||
print "name: %s" % (func.get("name","~empty~"))
|
print >> out, "name: %s" % (func.get("name","~empty~"))
|
||||||
print "file: %s (line %s)" % (func.get("file","~empty~"), func.get("line","~empty~"))
|
print >> out, "file: %s (line %s)" % (func.get("file","~empty~"), func.get("line","~empty~"))
|
||||||
print "is class: %s" % func.get("isclass",False)
|
print >> out, "is class: %s" % func.get("isclass",False)
|
||||||
print "is struct: %s" % func.get("isstruct",False)
|
print >> out, "is struct: %s" % func.get("isstruct",False)
|
||||||
print "module: %s" % func.get("module","~unknown~")
|
print >> out, "module: %s" % func.get("module","~unknown~")
|
||||||
print "namespace: %s" % func.get("namespace", "~empty~")
|
print >> out, "namespace: %s" % func.get("namespace", "~empty~")
|
||||||
print "class: %s" % (func.get("class","~empty~"))
|
print >> out, "class: %s" % (func.get("class","~empty~"))
|
||||||
print "method: %s" % (func.get("method","~empty~"))
|
print >> out, "method: %s" % (func.get("method","~empty~"))
|
||||||
print "brief: %s" % (func.get("brief","~empty~"))
|
print >> out, "brief: %s" % (func.get("brief","~empty~"))
|
||||||
if "decls" in func:
|
if "decls" in func:
|
||||||
print "declarations:"
|
print >> out, "declarations:"
|
||||||
for d in func["decls"]:
|
for d in func["decls"]:
|
||||||
print " %7s: %s" % (d[0], re.sub(r"[ ]+", " ", d[1]))
|
print >> out, " %7s: %s" % (d[0], re.sub(r"[ ]+", " ", d[1]))
|
||||||
if "seealso" in func:
|
if "seealso" in func:
|
||||||
print "seealso: ", func["seealso"]
|
print >> out, "seealso: ", func["seealso"]
|
||||||
if "params" in func:
|
if "params" in func:
|
||||||
print "parameters:"
|
print >> out, "parameters:"
|
||||||
for name, comment in func["params"].items():
|
for name, comment in func["params"].items():
|
||||||
print "%23s: %s" % (name, comment)
|
print >> out, "%23s: %s" % (name, comment)
|
||||||
if not skipped:
|
print >> out, "long: %s" % (func.get("long","~empty~"))
|
||||||
print "long: %s" % (func.get("long","~empty~"))
|
print >> out
|
||||||
print
|
|
||||||
|
|
||||||
def validate(self, func):
|
def validate(self, func):
|
||||||
if func.get("decls",None) is None:
|
if func.get("decls",None) is None:
|
||||||
if not func.get("isclass",False) and not func.get("isstruct",False):
|
if not func.get("isclass",False) and not func.get("isstruct",False):
|
||||||
return False
|
return False
|
||||||
if func["name"] in self.definitions:
|
if func["name"] in self.definitions:
|
||||||
print "RST parser error: \"%s\" from file: %s (line %s) is already documented in file: %s (line %s)" \
|
if show_errors:
|
||||||
% (func["name"], func["file"], func["line"], self.definitions[func["name"]]["file"], self.definitions[func["name"]]["line"])
|
print >> sys.stderr, "RST parser error: \"%s\" from file: %s (line %s) is already documented in file: %s (line %s)" \
|
||||||
return False
|
% (func["name"], func["file"], func["line"], self.definitions[func["name"]]["file"], self.definitions[func["name"]]["line"])
|
||||||
|
return False
|
||||||
return self.validateParams(func)
|
return self.validateParams(func)
|
||||||
|
|
||||||
def validateParams(self, func):
|
def validateParams(self, func):
|
||||||
@@ -369,13 +383,13 @@ class RstParser(object):
|
|||||||
|
|
||||||
# 1. all params are documented
|
# 1. all params are documented
|
||||||
for p in params:
|
for p in params:
|
||||||
if p not in documentedParams:
|
if p not in documentedParams and show_warnings:
|
||||||
print "RST parser warning: parameter \"%s\" of \"%s\" is undocumented. File: %s (line %s)" % (p, func["name"], func["file"], func["line"])
|
print >> sys.stderr, "RST parser warning: parameter \"%s\" of \"%s\" is undocumented. File: %s (line %s)" % (p, func["name"], func["file"], func["line"])
|
||||||
|
|
||||||
# 2. only real params are documented
|
# 2. only real params are documented
|
||||||
for p in documentedParams:
|
for p in documentedParams:
|
||||||
if p not in params:
|
if p not in params and show_warnings:
|
||||||
print "RST parser warning: unexisting parameter \"%s\" of \"%s\" is documented. File: %s (line %s)" % (p, func["name"], func["file"], func["line"])
|
print >> sys.stderr, "RST parser warning: unexisting parameter \"%s\" of \"%s\" is documented. File: %s (line %s)" % (p, func["name"], func["file"], func["line"])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def normalize(self, func):
|
def normalize(self, func):
|
||||||
@@ -435,40 +449,16 @@ class RstParser(object):
|
|||||||
if fname[6:] == func.get("name", ""):
|
if fname[6:] == func.get("name", ""):
|
||||||
func["name"] = fname[4:]
|
func["name"] = fname[4:]
|
||||||
func["method"] = fname[4:]
|
func["method"] = fname[4:]
|
||||||
else:
|
elif show_warnings:
|
||||||
print "RST parser warning: invalid definition of old C function \"%s\" - section name is \"%s\" instead of \"%s\". File: %s (line %s)" % (fname, func["name"], fname[6:], func["file"], func["line"])
|
print >> sys.stderr, "RST parser warning: invalid definition of old C function \"%s\" - section name is \"%s\" instead of \"%s\". File: %s (line %s)" % (fname, func["name"], fname[6:], func["file"], func["line"])
|
||||||
#self.print_info(func)
|
#self.print_info(func)
|
||||||
|
|
||||||
def normalizeText(self, s):
|
def normalizeText(self, s):
|
||||||
if s is None:
|
if s is None:
|
||||||
return s
|
return s
|
||||||
# normalize line endings
|
s = re.sub(r"\.\. math::[ ]*\n+(.*?)(\n[ ]*\n|$)", mathReplace2, s)
|
||||||
s = re.sub(r"\r\n", "\n", s)
|
s = re.sub(r":math:`([^`]+?)`", mathReplace, s)
|
||||||
# remove extra line breaks before/after _ or ,
|
s = re.sub(r" *:sup:", "^", s)
|
||||||
s = re.sub(r"\n[ ]*([_,])\n", r"\1 ", s)
|
|
||||||
# remove extra line breaks after `
|
|
||||||
#s = re.sub(r"`\n", "` ", s)
|
|
||||||
# remove extra space after ( and before )
|
|
||||||
s = re.sub(r"\([\n ]+", "(", s)
|
|
||||||
s = re.sub(r"[\n ]+\)", ")", s)
|
|
||||||
# remove extra line breaks after ".. note::"
|
|
||||||
s = re.sub(r"\.\. note::\n+", ".. note:: ", s)
|
|
||||||
# remove extra line breaks before *
|
|
||||||
s = re.sub(r"\n\n\*", "\n*", s)
|
|
||||||
# remove extra line breaks after *
|
|
||||||
s = re.sub(r"\n\*\n+", "\n* ", s)
|
|
||||||
# remove extra line breaks before #.
|
|
||||||
s = re.sub(r"\n\n#\.", "\n#.", s)
|
|
||||||
# remove extra line breaks after #.
|
|
||||||
s = re.sub(r"\n#\.\n+", "\n#. ", s)
|
|
||||||
# remove extra line breaks before `
|
|
||||||
#s = re.sub(r"\n[ ]*`", " `", s)
|
|
||||||
# remove trailing whitespaces
|
|
||||||
s = re.sub(r"[ ]+$", "", s)
|
|
||||||
# remove .. for references
|
|
||||||
s = re.sub(r"\.\. \[", "[", s)
|
|
||||||
# unescape
|
|
||||||
s = re.sub(r"\\(.)", "\\1", s)
|
|
||||||
|
|
||||||
s = s.replace(":ocv:class:", "")
|
s = s.replace(":ocv:class:", "")
|
||||||
s = s.replace(":ocv:struct:", "")
|
s = s.replace(":ocv:struct:", "")
|
||||||
@@ -491,8 +481,36 @@ class RstParser(object):
|
|||||||
# unwrap urls
|
# unwrap urls
|
||||||
s = re.sub(r"`([^`<]+ )<(https?://[^>]+)>`_", "\\1(\\2)", s)
|
s = re.sub(r"`([^`<]+ )<(https?://[^>]+)>`_", "\\1(\\2)", s)
|
||||||
# remove tailing ::
|
# remove tailing ::
|
||||||
s = re.sub(r"::$", "\n", s)
|
s = re.sub(r"::(\n|$)", "\\1", s)
|
||||||
|
|
||||||
|
# normalize line endings
|
||||||
|
s = re.sub(r"\r\n", "\n", s)
|
||||||
|
# remove extra line breaks before/after _ or ,
|
||||||
|
s = re.sub(r"\n[ ]*([_,])\n", r"\1 ", s)
|
||||||
|
# remove extra line breaks after `
|
||||||
|
#s = re.sub(r"`\n", "` ", s)
|
||||||
|
# remove extra space after ( and before .,)
|
||||||
|
s = re.sub(r"\([\n ]+", "(", s)
|
||||||
|
s = re.sub(r"[\n ]+(\.|,|\))", "\\1", s)
|
||||||
|
# remove extra line breaks after ".. note::"
|
||||||
|
s = re.sub(r"\.\. note::\n+", ".. note:: ", s)
|
||||||
|
# remove extra line breaks before *
|
||||||
|
s = re.sub(r"\n+\*", "\n*", s)
|
||||||
|
# remove extra line breaks after *
|
||||||
|
s = re.sub(r"\n\*\n+", "\n* ", s)
|
||||||
|
# remove extra line breaks before #.
|
||||||
|
s = re.sub(r"\n+#\.", "\n#.", s)
|
||||||
|
# remove extra line breaks after #.
|
||||||
|
s = re.sub(r"\n#\.\n+", "\n#. ", s)
|
||||||
|
# remove extra line breaks before `
|
||||||
|
#s = re.sub(r"\n[ ]*`", " `", s)
|
||||||
|
# remove trailing whitespaces
|
||||||
|
s = re.sub(r"[ ]+$", "", s)
|
||||||
|
# remove .. for references
|
||||||
|
#s = re.sub(r"\.\. \[", "[", s)
|
||||||
|
# unescape
|
||||||
|
s = re.sub(r"\\(.)", "\\1", s)
|
||||||
|
|
||||||
# remove whitespace before .
|
# remove whitespace before .
|
||||||
s = re.sub(r"[ ]+\.", ".", s)
|
s = re.sub(r"[ ]+\.", ".", s)
|
||||||
# remove tailing whitespace
|
# remove tailing whitespace
|
||||||
@@ -502,10 +520,13 @@ class RstParser(object):
|
|||||||
# compress line breaks
|
# compress line breaks
|
||||||
s = re.sub(r"\n\n+", "\n\n", s)
|
s = re.sub(r"\n\n+", "\n\n", s)
|
||||||
# remove other newlines
|
# remove other newlines
|
||||||
s = re.sub(r"([^.\n\\=])\n([^*#\n])", "\\1 \\2", s)
|
s = re.sub(r"([^.\n\\=])\n([^*#\n]|\*[^ ])", "\\1 \\2", s)
|
||||||
# compress whitespace
|
# compress whitespace
|
||||||
s = re.sub(r" +", " ", s)
|
s = re.sub(r" +", " ", s)
|
||||||
|
|
||||||
|
# restore math
|
||||||
|
s = re.sub(r" *<BR> *","\n", s)
|
||||||
|
|
||||||
# remove extra space before .
|
# remove extra space before .
|
||||||
s = re.sub(r"[\n ]+\.", ".", s)
|
s = re.sub(r"[\n ]+\.", ".", s)
|
||||||
|
|
||||||
@@ -516,11 +537,123 @@ class RstParser(object):
|
|||||||
|
|
||||||
s = s.strip()
|
s = s.strip()
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def printSummary(self):
|
||||||
|
print
|
||||||
|
print "RST Parser Summary:"
|
||||||
|
print " Total sections: %s" % self.sections_total
|
||||||
|
print " Skipped sections: %s" % self.sections_skipped
|
||||||
|
print " Parsed sections: %s" % self.sections_parsed
|
||||||
|
print " Invalid sections: %s" % (self.sections_total - self.sections_parsed - self.sections_skipped)
|
||||||
|
|
||||||
|
# statistic by language
|
||||||
|
stat = {}
|
||||||
|
classes = 0
|
||||||
|
structs = 0
|
||||||
|
for name, d in self.definitions.items():
|
||||||
|
if d.get("isclass", False):
|
||||||
|
classes += 1
|
||||||
|
elif d.get("isstruct", False):
|
||||||
|
structs += 1
|
||||||
|
else:
|
||||||
|
for decl in d.get("decls",[]):
|
||||||
|
stat[decl[0]] = stat.get(decl[0],0) + 1
|
||||||
|
|
||||||
|
print
|
||||||
|
print " classes documented: %s" % classes
|
||||||
|
print " structs documented: %s" % structs
|
||||||
|
for lang in sorted(stat.items()):
|
||||||
|
print " %7s functions documented: %s" % lang
|
||||||
|
|
||||||
|
def mathReplace2(match):
|
||||||
|
m = mathReplace(match)
|
||||||
|
#print "%s ===> %s" % (match.group(0), m)
|
||||||
|
return "\n\n"+m+"<BR><BR>"
|
||||||
|
|
||||||
|
def hdotsforReplace(match):
|
||||||
|
return '... '*int(match.group(1))
|
||||||
|
|
||||||
|
def matrixReplace(match):
|
||||||
|
m = match.group(2)
|
||||||
|
m = re.sub(r" *& *", " ", m)
|
||||||
|
return m
|
||||||
|
|
||||||
|
def mathReplace(match):
|
||||||
|
m = match.group(1)
|
||||||
|
|
||||||
|
m = m.replace("\n", "<BR>")
|
||||||
|
m = re.sub(r"\\text(tt|rm)?{(.*?)}", "\\2", m)
|
||||||
|
m = re.sub(r"\\mbox{(.*?)}", "\\1", m)
|
||||||
|
m = re.sub(r"\\mathrm{(.*?)}", "\\1", m)
|
||||||
|
m = re.sub(r"\\vecthree{(.*?)}{(.*?)}{(.*?)}", "[\\1 \\2 \\3]", m)
|
||||||
|
m = re.sub(r"\\bar{(.*?)}", "\\1`", m)
|
||||||
|
m = re.sub(r"\\sqrt\[(\d)*\]{(.*?)}", "sqrt\\1(\\2)", m)
|
||||||
|
m = re.sub(r"\\sqrt{(.*?)}", "sqrt(\\1)", m)
|
||||||
|
m = re.sub(r"\\frac{(.*?)}{(.*?)}", "(\\1)/(\\2)", m)
|
||||||
|
m = re.sub(r"\\fork{(.*?)}{(.*?)}{(.*?)}{(.*?)}", "\\1 \\2; \\3 \\4", m)
|
||||||
|
m = re.sub(r"\\forkthree{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}", "\\1 \\2; \\3 \\4; \\5 \\6", m)
|
||||||
|
m = re.sub(r"\\stackrel{(.*?)}{(.*?)}", "\\1 \\2", m)
|
||||||
|
m = re.sub(r"\\sum _{(.*?)}", "sum{by: \\1}", m)
|
||||||
|
|
||||||
|
m = re.sub(r" +", " ", m)
|
||||||
|
m = re.sub(r"\\begin{(?P<gtype>array|bmatrix)}(?:{[\|lcr\. ]+})? *(.*?)\\end{(?P=gtype)}", matrixReplace, m)
|
||||||
|
m = re.sub(r"\\hdotsfor{(\d+)}", hdotsforReplace, m)
|
||||||
|
m = re.sub(r"\\vecthreethree{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}{(.*?)}", "<BR>|\\1 \\2 \\3|<BR>|\\4 \\5 \\6|<BR>|\\7 \\8 \\9|<BR>", m)
|
||||||
|
|
||||||
|
m = re.sub(r"\\left[ ]*\\lfloor[ ]*", "[", m)
|
||||||
|
m = re.sub(r"[ ]*\\right[ ]*\\rfloor", "]", m)
|
||||||
|
m = re.sub(r"\\left[ ]*\([ ]*", "(", m)
|
||||||
|
m = re.sub(r"[ ]*\\right[ ]*\)", ")", m)
|
||||||
|
m = re.sub(r"([^\\])\$", "\\1", m)
|
||||||
|
|
||||||
|
m = m.replace("\\times", "x")
|
||||||
|
m = m.replace("\\pm", "+-")
|
||||||
|
m = m.replace("\\cdot", "*")
|
||||||
|
m = m.replace("\\sim", "~")
|
||||||
|
m = m.replace("\\leftarrow", "<-")
|
||||||
|
m = m.replace("\\rightarrow", "->")
|
||||||
|
m = m.replace("\\leftrightarrow", "<->")
|
||||||
|
m = re.sub(r" *\\neg *", " !", m)
|
||||||
|
m = re.sub(r" *\\neq? *", " != ", m)
|
||||||
|
m = re.sub(r" *\\geq? *", " >= ", m)
|
||||||
|
m = re.sub(r" *\\leq? *", " <= ", m)
|
||||||
|
m = re.sub(r" *\\vee *", " V ", m)
|
||||||
|
m = re.sub(r" *\\oplus *", " (+) ", m)
|
||||||
|
m = re.sub(r" *\\mod *", " mod ", m)
|
||||||
|
m = re.sub(r"( *)\\partial *", "\\1d", m)
|
||||||
|
|
||||||
|
m = re.sub(r"( *)\\quad *", "\\1 ", m)
|
||||||
|
m = m.replace("\\,", " ")
|
||||||
|
m = m.replace("\\:", " ")
|
||||||
|
m = m.replace("\\;", " ")
|
||||||
|
m = m.replace("\\!", "")
|
||||||
|
|
||||||
|
m = m.replace("\\\\", "<BR>")
|
||||||
|
m = m.replace("\\wedge", "/\\\\")
|
||||||
|
m = re.sub(r"\\(.)", "\\1", m)
|
||||||
|
|
||||||
|
m = re.sub(r"\([ ]+", "(", m)
|
||||||
|
m = re.sub(r"[ ]+(\.|,|\))(<BR>| |$)", "\\1\\2", m)
|
||||||
|
m = re.sub(r" +\|[ ]+([a-zA-Z0-9_(])", " |\\1", m)
|
||||||
|
m = re.sub(r"([a-zA-Z0-9_)}])[ ]+(\(|\|)", "\\1\\2", m)
|
||||||
|
|
||||||
|
m = re.sub(r"{\((-?[a-zA-Z0-9_]+)\)}", "\\1", m)
|
||||||
|
m = re.sub(r"{(-?[a-zA-Z0-9_]+)}", "(\\1)", m)
|
||||||
|
m = re.sub(r"\(([0-9]+)\)", "\\1", m)
|
||||||
|
m = m.replace("{", "(")
|
||||||
|
m = m.replace("}", ")")
|
||||||
|
|
||||||
|
#print "%s ===> %s" % (match.group(0), m)
|
||||||
|
return m
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print "Usage:\n", os.path.basename(sys.argv[0]), " <module path>"
|
print "Usage:\n", os.path.basename(sys.argv[0]), " <module path>"
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
if len(sys.argv) >= 3:
|
||||||
|
if sys.argv[2].lower() == "verbose":
|
||||||
|
verbose = True
|
||||||
|
|
||||||
rst_parser_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
rst_parser_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||||
hdr_parser_path = os.path.join(rst_parser_dir, "../python/src2")
|
hdr_parser_path = os.path.join(rst_parser_dir, "../python/src2")
|
||||||
@@ -543,34 +676,4 @@ if __name__ == "__main__":
|
|||||||
parser.parse(module, os.path.join(rst_parser_dir, "../" + module))
|
parser.parse(module, os.path.join(rst_parser_dir, "../" + module))
|
||||||
|
|
||||||
# summary
|
# summary
|
||||||
print
|
parser.printSummary()
|
||||||
print "RST Parser Summary:"
|
|
||||||
print " Total sections: %s" % parser.sections_total
|
|
||||||
print " Skipped sections: %s" % parser.sections_skipped
|
|
||||||
print " Parsed sections: %s" % parser.sections_parsed
|
|
||||||
print " Invalid sections: %s" % (parser.sections_total - parser.sections_parsed - parser.sections_skipped)
|
|
||||||
|
|
||||||
# statistic by language
|
|
||||||
stat = {}
|
|
||||||
classes = 0
|
|
||||||
structs = 0
|
|
||||||
for name, d in parser.definitions.items():
|
|
||||||
if d.get("isclass", False):
|
|
||||||
classes += 1
|
|
||||||
elif d.get("isstruct", False):
|
|
||||||
structs += 1
|
|
||||||
else:
|
|
||||||
for decl in d.get("decls",[]):
|
|
||||||
stat[decl[0]] = stat.get(decl[0],0) + 1
|
|
||||||
|
|
||||||
print
|
|
||||||
print " classes documented: %s" % classes
|
|
||||||
print " structs documented: %s" % structs
|
|
||||||
for lang in sorted(stat.items()):
|
|
||||||
print " %7s functions documented: %s" % lang
|
|
||||||
|
|
||||||
# sys.exit(0)
|
|
||||||
# for name, d in parser.definitions.items():
|
|
||||||
# print
|
|
||||||
# print ToJavadoc(d, d.get("params",{}).keys())
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user