Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>,
	Linux Doc Mailing List <linux-doc@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	intel-wired-lan@lists.osuosl.org,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org,
	Aleksandr Loktionov <aleksandr.loktionov@intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Akira Yokosawa <akiyks@gmail.com>
Subject: [Intel-wired-lan] [PATCH v4 31/41] docs: kdoc_re: Fix NestedMatch.sub() which causes PDF builds to break
Date: Sat, 31 Jan 2026 15:25:05 +0100	[thread overview]
Message-ID: <47bbc4753235edb31c9faec00bfa790f798a2ca0.1769867953.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1769867953.git.mchehab+huawei@kernel.org>

Having a "\digit"  inside a docstring with normal strings causes
PDF output to break, as it will add a weird character inside the
string. It should be using a raw string instead.

Yet, having r"\0" won't solve, as this would be converted in
Sphinx as "0". So, this has to be inside a pre formatted text.

That's said, the comment itself is probably not the best one.

Rewrite the entire comment to properly document each parameter
and add a "delim" parameter that will be passed to the
ancillary function.

Reported-by: Akira Yokosawa <akiyks@gmail.com>
Closes: https://lore.kernel.org/linux-doc/63e99049-cc72-4156-83af-414fdde34312@gmail.com/
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/lib/python/kdoc/kdoc_re.py | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/tools/lib/python/kdoc/kdoc_re.py b/tools/lib/python/kdoc/kdoc_re.py
index 886e33ffd2b9..f67ebe86c458 100644
--- a/tools/lib/python/kdoc/kdoc_re.py
+++ b/tools/lib/python/kdoc/kdoc_re.py
@@ -323,19 +323,28 @@ class NestedMatch:
 
         return args
 
-    def sub(self, sub, line, count=0):
-        """
-        This is similar to re.sub:
+    def sub(self, sub, line, delim=",", count=0):
+        r"""
+        Perform a regex‑based replacement on ``line`` for all matches with
+        the ``self.regex`` pattern. It uses the following parameters:
 
-        It matches a regex that it is followed by a delimiter,
-        replacing occurrences only if all delimiters are paired.
+        ``sub``
+            Replacement string that may contain placeholders in the form
+            ``\{digit}``, where  ``digit`` is an integer referring to the regex
+            capture group number.
 
-        if r'\0' is used, it works on a similar way of using re.group(0):
-        it places the entire args of the matched paired data, with the
-        delimiter stripped.
+            ``\{0}`` is a special case that expands to the entire matched text.
 
-        If count is different than zero, it will replace at most count
-        items.
+        ``line``
+            The string to operate on.
+
+        ``delim``
+            The delimiter used by identify the placeholder groups
+            (defaults to ",").
+
+        ``count``
+            Maximum number of replacements per match.  If 0 or omitted,
+            all matches are replaced.
         """
         out = ""
 
@@ -355,7 +364,7 @@ class NestedMatch:
             # replace arguments
             new_sub = sub
             if "\\" in sub:
-                args = self._split_args(value)
+                args = self._split_args(value, delim=delim)
 
                 new_sub = re.sub(r'\\(\d+)',
                                  lambda m: args[int(m.group(1))], new_sub)
-- 
2.52.0


  parent reply	other threads:[~2026-01-31 14:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-31 14:24 [Intel-wired-lan] [PATCH v4 00/41] kernel-doc: make it parse new functions and structs Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 01/41] docs: kdoc_re: add support for groups() Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 02/41] docs: kdoc_re: don't go past the end of a line Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 03/41] docs: kdoc_parser: move var transformers to the beginning Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 04/41] docs: kdoc_parser: don't mangle with function defines Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 05/41] docs: kdoc_parser: add functions support for NestedMatch Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 06/41] docs: kdoc_parser: use NestedMatch to handle __attribute__ on functions Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 07/41] docs: kdoc_parser: fix variable regexes to work with size_t Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 08/41] docs: kdoc_parser: fix the default_value logic for variables Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 09/41] docs: kdoc_parser: add some debug for variable parsing Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 10/41] docs: kdoc_parser: don't exclude defaults from prototype Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 11/41] docs: kdoc_parser: fix parser to support multi-word types Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 12/41] docs: kdoc_parser: ignore context analysis and lock attributes Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 13/41] docs: kdoc_parser: add support for LIST_HEAD Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 14/41] docs: kdoc_parser: handle struct member macro VIRTIO_DECLARE_FEATURES(name) Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 15/41] docs: kdoc_re: properly handle strings and escape chars on it Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 16/41] docs: kdoc_re: better show KernRe() at documentation Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 17/41] docs: kdoc_re: don't recompile NestedMatch regex every time Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 18/41] docs: kdoc_re: Change NestedMath args replacement to \0 Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 19/41] docs: kdoc_re: make NestedMatch use KernRe Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 20/41] docs: kdoc_re: add support on NestedMatch for argument replacement Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 21/41] docs: kdoc_parser: better handle struct_group macros Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 22/41] docs: kdoc_re: fix a parse bug on struct page_pool_params Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 23/41] docs: kdoc_re: add a helper class to declare C function matches Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 24/41] docs: kdoc_parser: use the new CFunction class Mauro Carvalho Chehab
2026-01-31 14:24 ` [Intel-wired-lan] [PATCH v4 25/41] docs: kdoc_parser: minimize differences with struct_group_tagged Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 26/41] docs: kdoc_parser: move transform lists to a separate file Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 27/41] docs: kdoc_re: don't remove the trailing "; " with NestedMatch Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 28/41] docs: kdoc_re: prevent adding whitespaces on sub replacements Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 29/41] docs: xforms_lists.py: use CFuntion to handle all function macros Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 30/41] docs: kdoc_files: allows the caller to use a different xforms class Mauro Carvalho Chehab
2026-01-31 14:25 ` Mauro Carvalho Chehab [this message]
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 32/41] docs: sphinx-build-wrapper: allow -v override -q Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 33/41] tools: sphinx-build-wrapper: improve its help message Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 34/41] docs: kdoc_files: document KernelFiles() ABI Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 35/41] docs: kdoc_output: add optional args to ManOutput class Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 36/41] docs: sphinx-build-wrapper: better handle troff .TH markups Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 37/41] docs: kdoc_output: use a more standard order for .TH on man pages Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 38/41] docs: kdoc_output: describe the class init parameters Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 39/41] docs: kdoc_output: pick a better default for modulename Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 40/41] docs: python: add helpers to run unit tests Mauro Carvalho Chehab
2026-01-31 14:25 ` [Intel-wired-lan] [PATCH v4 41/41] tools: unittests: add tests for kernel-doc NestedMatch and KernRe Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47bbc4753235edb31c9faec00bfa790f798a2ca0.1769867953.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=akiyks@gmail.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=corbet@lwn.net \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox