From 9f3328c901099a6089ee2a055410b2f05c380d62 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Tue, 20 Aug 2024 22:03:10 -0500 Subject: [PATCH] [sourcegen] Roll back some changes --- .../sourcegen/sourcegen/_HeaderFileParser.py | 68 ++----------------- 1 file changed, 4 insertions(+), 64 deletions(-) diff --git a/interfaces/sourcegen/sourcegen/_HeaderFileParser.py b/interfaces/sourcegen/sourcegen/_HeaderFileParser.py index 9d2041b0e7..0b6fea5481 100644 --- a/interfaces/sourcegen/sourcegen/_HeaderFileParser.py +++ b/interfaces/sourcegen/sourcegen/_HeaderFileParser.py @@ -20,10 +20,6 @@ class HeaderFileParser: - @classmethod - def _parse_func(cls, func_comment: tuple[str, str]) -> Func: - return Func.from_str(*func_comment) - def __init__(self, path: Path, ignore_funcs: List[str] = None): self._path = path self._ignore_funcs = ignore_funcs @@ -69,56 +65,14 @@ def parse_h(cls, ignore_files, ignore_funcs) -> List[HeaderFile]: def _parse_h(self) -> HeaderFile: ct = self._path.read_text() - def parse_with_doxygen(text): - # a primitive doxygen parser for existing Cantera CLib header files - regex = re.compile(( - r"(?P\n\s*\n)|" # blank line - r"(?P(?=//! )[^\n]*)|" # leading doxygen comment - r"(?P(?=CANTERA_CAPI)[^;]*;)|" # CLib function - r"(?P(?=//!< )[^\n]*)")) # trailing doxygen comment - matches = re.finditer(regex, text) - - pairs = [] - function = None - comments = [] - for m in matches: - if function: - if m.group("func"): - # new function: flush buffers - pairs.append((function, "\n".join(comments))) - comments = [] - function = m.group("func").replace("CANTERA_CAPI ", "") - elif m.group("head"): - # new heading comment: flush buffers - pairs.append((function, "\n".join(comments))) - comments = [m.group("head")] - function = None - elif m.group("tail"): - # trailing comment: append to buffer - comments.append(m.group("tail")) - else: # m.group("blank"): - # blank line: flush buffers - pairs.append((function, "\n".join(comments))) - comments = [] - function = None - else: - if m.group("blank"): - # blank line: clear buffer - comments = [] - elif m.group("head"): - # new heading comment: buffer - comments.append(m.group("head")) - elif m.group("func"): - # new function: buffer - function = m.group("func").replace("CANTERA_CAPI ", "") - return pairs - - c_functions = parse_with_doxygen(ct) + matches = re.finditer(r"CANTERA_CAPI.*?;", ct, re.DOTALL) + c_functions = [re.sub(r"\s+", " ", m.group()).replace("CANTERA_CAPI ", "") + for m in matches] if not c_functions: return - parsed = map(self._parse_func, c_functions) + parsed = map(Func.from_str, c_functions) logger.info(f" parsing {self._path.name}") if self._ignore_funcs: @@ -130,17 +84,3 @@ def parse_with_doxygen(text): return return HeaderFile(self._path, parsed) - - -def doxygen_func(tag: str, text: str) -> str: - """Extract function signature from doxygen tag if it exists.""" - regex = re.compile(rf"(?<={tag} ).*[^\(\n]|((?<={tag} )(.*?)\))") - matched = list(re.finditer(regex, text)) - if not matched: - return "" - if len(matched) > 1: - msg = f"Found more than one {tag!r} annotation; returning first." - logging.warning(msg) - signatures = '\n - '.join([""] + [_[0] for _ in matched]) - logging.debug("Found instances:%s", signatures) - return matched[0][0]