[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <IA3PR11MB8986D6ED3B745849C887C296E591A@IA3PR11MB8986.namprd11.prod.outlook.com>
Date: Wed, 28 Jan 2026 17:49:04 +0000
From: "Loktionov, Aleksandr" <aleksandr.loktionov@...el.com>
To: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>, Jonathan Corbet
<corbet@....net>, Linux Doc Mailing List <linux-doc@...r.kernel.org>
CC: "bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"intel-wired-lan@...ts.osuosl.org" <intel-wired-lan@...ts.osuosl.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>, Peter Zijlstra
<peterz@...radead.org>, Randy Dunlap <rdunlap@...radead.org>, "Stephen
Rothwell" <sfr@...b.auug.org.au>
Subject: RE: [Intel-wired-lan] [PATCH v2 20/25] tools: kdoc_re: add support on
NestedMatch for argument replacement
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@...osl.org> On Behalf
> Of Mauro Carvalho Chehab
> Sent: Wednesday, January 28, 2026 5:50 PM
> To: Jonathan Corbet <corbet@....net>; Linux Doc Mailing List <linux-
> doc@...r.kernel.org>
> Cc: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>;
> bpf@...r.kernel.org; intel-wired-lan@...ts.osuosl.org; linux-
> kernel@...r.kernel.org; netdev@...r.kernel.org; Peter Zijlstra
> <peterz@...radead.org>; Randy Dunlap <rdunlap@...radead.org>; Stephen
> Rothwell <sfr@...b.auug.org.au>
> Subject: [Intel-wired-lan] [PATCH v2 20/25] tools: kdoc_re: add
> support on NestedMatch for argument replacement
>
> Currently, NestedMatch has very limited support for aguments
> replacement: it is all or nothing.
>
> Add support to allow replacing individual arguments as well.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
> ---
> tools/lib/python/kdoc/kdoc_re.py | 61 ++++++++++++++++++++++++++++++-
> -
> 1 file changed, 59 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/python/kdoc/kdoc_re.py
> b/tools/lib/python/kdoc/kdoc_re.py
> index aabfd6c4fd71..f49a568b9155 100644
> --- a/tools/lib/python/kdoc/kdoc_re.py
> +++ b/tools/lib/python/kdoc/kdoc_re.py
> @@ -267,6 +267,59 @@ class NestedMatch:
>
> yield line[t[0]:t[2]]
>
> + @staticmethod
> + def _split_args(all_args, delim=","):
> + """
> + Helper method to split comma-separated function arguments
> + or struct elements, if delim is set to ";".
> +
> + It returns a list of arguments that can be used later on by
> + the sub() method.
> + """
> + args = [all_args]
> + stack = []
> + arg_start = 0
> + string_char = None
> + escape = False
> +
> + for idx, d in enumerate(all_args):
> + if escape:
> + escape = False
> + continue
> +
> + if string_char:
> + if d == '\\':
> + escape = True
> + elif d == string_char:
> + string_char = None
> +
> + continue
> +
> + if d in ('"', "'"):
> + string_char = d
> + continue
> +
> + if d in DELIMITER_PAIRS:
> + end = DELIMITER_PAIRS[d]
> +
> + stack.append(end)
> + continue
> +
> + if stack and d == stack[-1]:
> + stack.pop()
> + continue
> +
> + if d == delim and not stack:
> + args.append(all_args[arg_start:idx].strip())
> + arg_start = idx + 1
> +
> + # Add the last argument (if any)
> + last = all_args[arg_start:].strip()
> + if last:
> + args.append(last)
> +
> + return args
> +
> def sub(self, sub, line, count=0):
> """
> This is similar to re.sub:
> @@ -292,9 +345,13 @@ class NestedMatch:
> # Value, ignoring start/end delimiters
> value = line[end:pos - 1]
>
> - # replaces \0 at the sub string, if \0 is used there
> + # replace arguments
> new_sub = sub
> - new_sub = new_sub.replace(r'\0', value)
> + if "\\" in sub:
> + args = self._split_args(value)
> +
> + new_sub = re.sub(r'\\(\d+)',
> + lambda m: args[int(m.group(1))],
> new_sub)
>
> out += new_sub
>
> --
> 2.52.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@...el.com>
Powered by blists - more mailing lists