Fixed few more bugs in rst_parser. Fixed small typos in documentation.
authorAndrey Kamaev <no@email>
Fri, 8 Jul 2011 04:31:13 +0000 (04:31 +0000)
committerAndrey Kamaev <no@email>
Fri, 8 Jul 2011 04:31:13 +0000 (04:31 +0000)
modules/core/doc/basic_structures.rst
modules/java/rst_parser.py

index 0ea399a..1fd60a6 100644 (file)
@@ -113,7 +113,7 @@ Rect\_
 ------
 .. ocv:class:: Rect_
 
-Template class for 2D rectangles, described by the following parameters::
+Template class for 2D rectangles, described by the following parameters:
 
 * Coordinates of the top-left corner. This is a default interpretation of ``Rect_::x`` and ``Rect_::y`` in OpenCV. Though, in your algorithms you may count ``x`` and ``y`` from the bottom-left corner. 
 * Rectangle width and height.
@@ -802,7 +802,7 @@ Provides matrix assignment operators.
 
 .. ocv:function:: Mat& Mat::operator = (const MatExpr_Base& expr)
 
-.. ocv:function:: Mat& operator = (const Scalar& s)
+.. ocv:function:: Mat& Mat::operator = (const Scalar& s)
 
     :param m: Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that no data is copied but the data is shared and the reference counter, if any, is incremented. Before assigning new data, the old data is de-referenced via  :ocv:func:`Mat::release` .
 
@@ -855,7 +855,7 @@ The method makes a new header for the specified matrix row and returns it. This
         A.row(i) = A.row(j) + 0;
 
         // this is a bit longe, but the recommended method.
-        Mat Ai = A.row(i); M.row(j).copyTo(Ai);
+        A.row(j).copyTo(A.row(i));
 
 Mat::col
 ------------
index 6ef1b27..761d2f4 100644 (file)
@@ -129,7 +129,7 @@ class RstParser(object):
 
             # continue capture seealso
             if capturing_seealso:
-                if l.startswith(" "):
+                if not l or l.startswith(" "):
                     seealso = func.get("seealso",[])
                     seealso.extend(l.split(","))
                     func["seealso"] = seealso
@@ -158,14 +158,7 @@ class RstParser(object):
                     continue
                 else:
                     skip_code_lines = False
-
-            if ll.startswith(".. "):
-                expected_brief = False
-            elif ll.endswith("::"):
-                # turn on line-skipping mode for code fragments
-                skip_code_lines = True
-                ll = ll[:len(ll)-2]
-
+                    
             if ll.startswith(".. code-block::") or ll.startswith(".. math::") or ll.startswith(".. image::"):
                 skip_code_lines = True
                 continue
@@ -175,6 +168,13 @@ class RstParser(object):
                 skip_code_lines = True
                 continue
 
+            if ll.startswith(".. "):
+                expected_brief = False
+            elif ll.endswith("::"):
+                # turn on line-skipping mode for code fragments
+                skip_code_lines = True
+                ll = ll[:len(ll)-2]
+
             # parse ".. seealso::" blocks
             if ll.startswith(".. seealso::"):
                 if ll.endswith(".. seealso::"):
@@ -227,6 +227,8 @@ class RstParser(object):
 
             # record other lines as long description
             func["long"] = func.get("long", "") + "\n" + ll
+            if skip_code_lines:
+                func["long"] = func.get("long", "") + "\n"
         # endfor l in lines
         
         if fdecl.balance != 0:
@@ -406,9 +408,11 @@ class RstParser(object):
             seealso = []
             for see in func["seealso"]:
                 item = self.normalizeText(see.rstrip(".")).strip("\"")
-                if item:
+                if item and (item.find(" ") < 0 or item.find("::operator") > 0):
                     seealso.append(item)
             func["seealso"] = list(set(seealso))
+            if not func["seealso"]:
+                del func["seealso"]
 
         # special case for old C functions - section name should omit "cv" prefix
         if not func.get("isclass",False) and not func.get("isstruct",False):
@@ -444,9 +448,12 @@ class RstParser(object):
         # remove tailing ::
         s = re.sub(r"::$", "\n", s)
         # remove extra line breaks before/after _ or ,
-        s = re.sub(r"\n[ ]*([_,])\n", r"\1", 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 *
@@ -461,32 +468,52 @@ class RstParser(object):
         s = re.sub(r"\n[ ]*`", " `", s)
         # remove trailing whitespaces
         s = re.sub(r"[ ]+$", "", s)
-        # remove whitespace before .
-        s = re.sub(r"[ ]+\.", "\.", s)
         # remove .. for references
         s = re.sub(r"\.\. \[", "[", s)
         # unescape
         s = re.sub(r"\\(.)", "\\1", s)
-        # compress whitespace
-        s = re.sub(r" +", " ", s)
-        # compress linebreaks
-        s = re.sub(r"\n\n+", "\n\n", s)
-
-        s = s.replace("**", "")
-        s = s.replace("``", "\"")
-        s = s.replace("`", "\"")
-        s = s.replace("\"\"", "\"")
-        s = s.replace(":ocv:cfunc:","")
-        s = s.replace(":ref:", "")
-        s = s.replace(":math:", "")
+        
         s = s.replace(":ocv:class:", "")
+        s = s.replace(":ocv:struct:", "")
         s = s.replace(":ocv:func:", "")
+        s = s.replace(":ocv:cfunc:","")
         s = s.replace(":c:type:", "")
+        s = s.replace(":c:func:", "")
+        s = s.replace(":ref:", "")
+        s = s.replace(":math:", "")
+        s = s.replace(":func:", "")
+
         s = s.replace("]_", "]")
         s = s.replace(".. note::", "Note:")
         s = s.replace(".. ocv:function::", "")
         s = s.replace(".. ocv:cfunction::", "")
 
+        # remove ".. identifier:" lines
+        s = re.sub(r"(^|\n)\.\. [a-zA-Z_0-9]+(::[a-zA-Z_0-9]+)?:(\n|$)", "\n ", s)
+        # unwrap urls
+        s = re.sub(r"`([^`<]+ )<(https?://[^>]+)>`_", "\\1(\\2)", s)
+        
+        # remove whitespace before .
+        s = re.sub(r"[ ]+\.", ".", s)
+        # remove tailing whitespace
+        s = re.sub(r" +(\n|$)", "\\1", s)
+        # remove leading whitespace
+        s = re.sub(r"(^|\n) +", "\\1", s)
+        # compress line breaks
+        s = re.sub(r"\n\n+", "\n\n", s)
+        # remove other newlines
+        s = re.sub(r"([^.\n])\n([^*#\n])", "\\1 \\2", s)
+        # compress whitespace
+        s = re.sub(r" +", " ", s)
+
+        # remove extra space before .
+        s = re.sub(r"[\n ]+\.", ".", s)
+
+        s = s.replace("**", "")
+        s = s.replace("``", "\"")
+        s = s.replace("`", "\"")
+        s = s.replace("\"\"", "\"")
+
         s = s.strip()
         return s
 
@@ -510,7 +537,7 @@ if __name__ == "__main__":
     parser = RstParser(hdr_parser.CppHeaderParser())
     
     if module == "all":
-        for m in ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "ocl", "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(rst_parser_dir, "../" + m))
     else:
         parser.parse(module, os.path.join(rst_parser_dir, "../" + module))