improve parsing of module comments
MODIFY
gen_rust.py
gen_rust.py
@@ -2181,7 +2181,7 @@ class RustWrapperGenerator(object):
self.namespaces = set(str(x.replace(".", "::")) for x in parser.namespaces)
logging.info("\n\n=============== Header: %s ================\n\n", hdr)
logging.info("Namespaces: %s", parser.namespaces)
- logging.info("Comment: %s", parser.comment)
+ logging.info("Comment: %s", parser.module_comment)
includes.append('#include "' + hdr + '"')
for decl in decls:
logging.info("\n--- Incoming ---\n%s", pformat(decl, 4))
@@ -2200,7 +2200,7 @@ class RustWrapperGenerator(object):
self.moduleRustExterns = StringIO()
self.moduleSafeRust.write('//! <script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>\n'.encode("utf-8"))
- self.moduleSafeRust.write(self.reformat_doc(parser.comment, "//!"))
+ self.moduleSafeRust.write(self.reformat_doc(parser.module_comment.get(module, ""), "//!"))
self.moduleSafeRust.write(template("""
use std::os::raw::{c_char, c_void};

MODIFY
hdr_parser.py
hdr_parser.py
#!/usr/bin/env python
from __future__ import print_function
-import os, sys, re, string, io
+
+import io
+import re
+import sys
# the list only for debugging. The real list, used in the real OpenCV build, is specified in CMakeLists.txt
opencv_hdr_list = [
@@ -43,7 +46,7 @@ class CppHeaderParser(object):
self.ACTUAL_PUBLIC_SECTION = 5
self.namespaces = set()
- self.comment = None
+ self.module_comment = {}
def batch_replace(self, s, pairs):
for before, after in pairs:
@@ -861,6 +864,9 @@ class CppHeaderParser(object):
docstring += l + "\n"
continue
docstring += l[:pos] + "\n"
+ m = re.search(r"@defgroup\s+(\w+)\b", docstring)
+ if m:
+ self.module_comment[m.group(1)] = docstring
l = l[pos+2:]
state = SCAN
@@ -951,8 +957,6 @@ class CppHeaderParser(object):
if stmt_type == "namespace":
chunks = [block[1] for block in self.block_stack if block[0] == 'namespace'] + [name]
self.namespaces.add('.'.join(chunks))
- if self.comment == None:
- self.comment = docstring
else:
stmt_type, name, parse_flag = "block", "", False

improve parsing of module comments