mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 05:53:34 +08:00
modules documentation: ignore comments in source files
This commit is contained in:
@@ -247,12 +247,19 @@ class SourceParser(object):
|
|||||||
self._modules = {} # all found modules: key is the module name
|
self._modules = {} # all found modules: key is the module name
|
||||||
self._consistency_checks_failure = False # one or more checks failed
|
self._consistency_checks_failure = False # one or more checks failed
|
||||||
|
|
||||||
|
self._comment_remove_pattern = re.compile(
|
||||||
|
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
|
||||||
|
re.DOTALL | re.MULTILINE)
|
||||||
|
|
||||||
def Parse(self, scope, contents):
|
def Parse(self, scope, contents):
|
||||||
"""
|
"""
|
||||||
Incrementally parse program contents and append all found documentations
|
Incrementally parse program contents and append all found documentations
|
||||||
to the list.
|
to the list.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# remove comments from source
|
||||||
|
contents = self._comment_remover(contents)
|
||||||
|
|
||||||
extracted_function_calls = [] # list of tuples: (FUNC_NAME, list(ARGS))
|
extracted_function_calls = [] # list of tuples: (FUNC_NAME, list(ARGS))
|
||||||
|
|
||||||
start_index = 0
|
start_index = 0
|
||||||
@@ -302,6 +309,16 @@ class SourceParser(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _comment_remover(self, text):
|
||||||
|
""" remove C++ & C style comments.
|
||||||
|
Source: https://stackoverflow.com/a/241506 """
|
||||||
|
def replacer(match):
|
||||||
|
s = match.group(0)
|
||||||
|
if s.startswith('/'):
|
||||||
|
return " " # note: a space and not an empty string
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
return re.sub(self._comment_remove_pattern, replacer, text)
|
||||||
|
|
||||||
def _do_consistency_check(self, contents, scope, module_doc):
|
def _do_consistency_check(self, contents, scope, module_doc):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user