From 3751acca65569ac2a468e8dc3fd02e2b5b5957d7 Mon Sep 17 00:00:00 2001 From: Gereon Kremer Date: Mon, 4 Apr 2022 15:38:25 -0700 Subject: [PATCH] Fix links when converting kinds documentation to python (#8557) This mainly fixes explicit rst links when we convert the kinds comments to python. --- src/api/python/genenums.py.in | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/api/python/genenums.py.in b/src/api/python/genenums.py.in index dc3c4774c..b92439ee1 100644 --- a/src/api/python/genenums.py.in +++ b/src/api/python/genenums.py.in @@ -62,25 +62,28 @@ class {enum}(Enum): ENUMS_ATTR_TEMPLATE = r''' {name}=c_{enum}.{cpp_name}, """{doc}""" ''' -comment_repls = { - 'Term::([a-zA-Z]+)\(([^)]*)\)': ':py:meth:`Term.\\1()`', - 'Solver::([a-zA-Z]+)\(([^)]*)\) const': ':py:meth:`Solver.\\1()`', - 'Solver::([a-zA-Z]+)\(([^)]*)\)': ':py:meth:`Solver.\\1()`', - 'DatatypeConstructor::([a-zA-Z]+)\(([^)]*)\) const': ':py:meth:`DatatypeConstructor.\\1()`', - 'DatatypeConstructor::([a-zA-Z]+)\(([^)]*)\)': ':py:meth:`DatatypeConstructor.\\1()`', - 'Datatype::([a-zA-Z]+)\(([^)]*)\) const': ':py:meth:`Datatype.\\1()`', - 'Datatype::([a-zA-Z]+)\(([^)]*)\)': ':py:meth:`Datatype.\\1()`', - 'DatatypeSelector::([a-zA-Z]+)\(([^)]*)\) const': ':py:meth:`DatatypeSelector.\\1()`', - 'DatatypeSelector::([a-zA-Z]+)\(([^)]*)\)': ':py:meth:`DatatypeSelector.\\1()`', - ':cpp:func:`(.*?)`': '\\1', - ':cpp:enumerator:`(.*?)`': ':py:obj:`\\1`', - '\\\\': '\\\\\\\\', -} +# list to enforce proper ordering +comment_repls = [ + # first remove explicit cpp references + (':cpp:func:`(.*?)`', '\\1'), + (':cpp:enumerator:`(.*?)`', ':py:obj:`\\1`'), + # introduce proper python references + ('Term::([a-zA-Z]+)\(([^)]*)\)', ':py:meth:`Term.\\1()`'), + ('Solver::([a-zA-Z]+)\(([^)]*)\) const', ':py:meth:`Solver.\\1()`'), + ('Solver::([a-zA-Z]+)\(([^)]*)\)', ':py:meth:`Solver.\\1()`'), + ('DatatypeConstructor::([a-zA-Z]+)\(([^)]*)\) const', ':py:meth:`DatatypeConstructor.\\1()`'), + ('DatatypeConstructor::([a-zA-Z]+)\(([^)]*)\)', ':py:meth:`DatatypeConstructor.\\1()`'), + ('Datatype::([a-zA-Z]+)\(([^)]*)\) const', ':py:meth:`Datatype.\\1()`'), + ('Datatype::([a-zA-Z]+)\(([^)]*)\)', ':py:meth:`Datatype.\\1()`'), + ('DatatypeSelector::([a-zA-Z]+)\(([^)]*)\) const', ':py:meth:`DatatypeSelector.\\1()`'), + ('DatatypeSelector::([a-zA-Z]+)\(([^)]*)\)', ':py:meth:`DatatypeSelector.\\1()`'), + ('\\\\', '\\\\\\\\'), +] def reformat_comment(comment): # apply replacements from above - for pat, repl in comment_repls.items(): + for pat, repl in comment_repls: comment = re.sub(pat, repl, comment) # remove duplicate lines (e.g. overloads collapse from previous substitutions) comment = re.sub('^(?P.*)$\n^(?P=line)$', '\\g', comment, flags=re.MULTILINE) -- 2.30.2