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>,
bpf@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Randy Dunlap <rdunlap@infradead.org>,
Stephen Rothwell <sfr@canb.auug.org.au>
Subject: [Intel-wired-lan] [PATCH v2 05/25] docs: kdoc_parser: add functions support for NestedMatch
Date: Wed, 28 Jan 2026 17:50:03 +0100 [thread overview]
Message-ID: <43b1fb838ba73c3efc18ab605b892f531ffbed01.1769617841.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1769617841.git.mchehab+huawei@kernel.org>
Some annotations macros may have nested parenthesis, causing normal
regex parsing to fail.
Extend apply_transforms to also use NestedMatch and add support
for nested functions.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
---
tools/lib/python/kdoc/kdoc_parser.py | 38 ++++++++++++++++++----------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/tools/lib/python/kdoc/kdoc_parser.py b/tools/lib/python/kdoc/kdoc_parser.py
index 3ba2cda2487a..ae5b2ef80f75 100644
--- a/tools/lib/python/kdoc/kdoc_parser.py
+++ b/tools/lib/python/kdoc/kdoc_parser.py
@@ -152,7 +152,7 @@ struct_xforms = [
(KernRe(r'DEFINE_DMA_UNMAP_LEN\s*\(' + struct_args_pattern + r'\)', re.S), r'__u32 \1'),
]
#
-# Regexes here are guaranteed to have the end delimiter matching
+# Struct regexes here are guaranteed to have the end delimiter matching
# the start delimiter. Yet, right now, only one replace group
# is allowed.
#
@@ -160,6 +160,13 @@ struct_nested_prefixes = [
(re.compile(r'\bSTRUCT_GROUP\('), r'\1'),
]
+#
+# Function Regexes here are guaranteed to have the end delimiter matching
+# the start delimiter.
+#
+function_nested_prefixes = [
+]
+
#
# Transforms for function prototypes
#
@@ -207,13 +214,6 @@ var_xforms = [
# Ancillary functions
#
-def apply_transforms(xforms, text):
- """
- Apply a set of transforms to a block of text.
- """
- for search, subst in xforms:
- text = search.sub(subst, text)
- return text
multi_space = KernRe(r'\s\s+')
def trim_whitespace(s):
@@ -408,6 +408,8 @@ class KernelDoc:
# Place all potential outputs into an array
self.entries = []
+ self.nested = NestedMatch()
+
#
# We need Python 3.7 for its "dicts remember the insertion
# order" guarantee
@@ -505,6 +507,16 @@ class KernelDoc:
# State flags
self.state = state.NORMAL
+ def apply_transforms(self, regex_xforms, nested_xforms, text):
+ """Apply a set of transforms to a block of text."""
+ for search, subst in regex_xforms:
+ text = search.sub(subst, text)
+
+ for search, sub in nested_xforms:
+ text = self.nested.sub(search, sub, text)
+
+ return text.strip()
+
def push_parameter(self, ln, decl_type, param, dtype,
org_arg, declaration_name):
"""
@@ -881,11 +893,9 @@ class KernelDoc:
# Go through the list of members applying all of our transformations.
#
members = trim_private_members(members)
- members = apply_transforms(struct_xforms, members)
+ members = self.apply_transforms(struct_xforms, struct_nested_prefixes,
+ members)
- nested = NestedMatch()
- for search, sub in struct_nested_prefixes:
- members = nested.sub(search, sub, members)
#
# Deal with embedded struct and union members, and drop enums entirely.
#
@@ -1088,7 +1098,9 @@ class KernelDoc:
#
# Apply the initial transformations.
#
- prototype = apply_transforms(function_xforms, prototype)
+ prototype = self.apply_transforms(function_xforms,
+ function_nested_prefixes,
+ prototype)
# Yes, this truly is vile. We are looking for:
# 1. Return type (may be nothing if we're looking at a macro)
--
2.52.0
next prev parent reply other threads:[~2026-01-28 16:50 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 16:49 [Intel-wired-lan] [PATCH v2 00/25] kernel-doc: make it parse new functions and structs Mauro Carvalho Chehab
2026-01-28 16:49 ` [Intel-wired-lan] [PATCH v2 01/25] docs: kdoc_re: add support for groups() Mauro Carvalho Chehab
2026-01-28 17:44 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 02/25] docs: kdoc_re: don't go past the end of a line Mauro Carvalho Chehab
2026-01-28 17:44 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 03/25] docs: kdoc_parser: move var transformers to the beginning Mauro Carvalho Chehab
2026-01-28 17:44 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 04/25] docs: kdoc_parser: don't mangle with function defines Mauro Carvalho Chehab
2026-01-28 17:45 ` Loktionov, Aleksandr
2026-01-28 16:50 ` Mauro Carvalho Chehab [this message]
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 06/25] docs: kdoc_parser: use NestedMatch to handle __attribute__ on functions Mauro Carvalho Chehab
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 07/25] docs: kdoc_parser: fix variable regexes to work with size_t Mauro Carvalho Chehab
2026-01-28 17:45 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 08/25] docs: kdoc_parser: fix the default_value logic for variables Mauro Carvalho Chehab
2026-01-28 17:45 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 09/25] docs: kdoc_parser: add some debug for variable parsing Mauro Carvalho Chehab
2026-01-28 17:46 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 10/25] docs: kdoc_parser: don't exclude defaults from prototype Mauro Carvalho Chehab
2026-01-28 17:46 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 11/25] docs: kdoc_parser: fix parser to support multi-word types Mauro Carvalho Chehab
2026-01-28 17:47 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 12/25] docs: kdoc_parser: ignore context analysis and lock attributes Mauro Carvalho Chehab
2026-01-28 17:47 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 13/25] docs: kdoc_parser: add support for LIST_HEAD Mauro Carvalho Chehab
2026-01-28 17:47 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 14/25] kdoc_parser: handle struct member macro VIRTIO_DECLARE_FEATURES(name) Mauro Carvalho Chehab
2026-01-28 17:47 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 15/25] docs: kdoc_re: properly handle strings and escape chars on it Mauro Carvalho Chehab
2026-01-28 17:47 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 16/25] docs: kdoc_re: better show KernRe() at documentation Mauro Carvalho Chehab
2026-01-28 17:48 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 17/25] docs: kdoc_re: don't recompile NextMatch regex every time Mauro Carvalho Chehab
2026-01-28 17:48 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 18/25] docs: kdoc_re: Change NestedMath args replacement to \0 Mauro Carvalho Chehab
2026-01-28 17:48 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 19/25] docs: kdoc_re: make NextedMatch use KernRe Mauro Carvalho Chehab
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 20/25] tools: kdoc_re: add support on NestedMatch for argument replacement Mauro Carvalho Chehab
2026-01-28 17:49 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 21/25] tools: python: add helpers to run unit tests Mauro Carvalho Chehab
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 22/25] unittests: add tests for NestedMatch class Mauro Carvalho Chehab
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 23/25] tools/lib/python/unittest_helper.py Mauro Carvalho Chehab
2026-01-28 17:17 ` Mauro Carvalho Chehab
2026-01-28 17:32 ` Loktionov, Aleksandr
2026-01-28 18:09 ` Jacob Keller
2026-01-28 21:02 ` Mauro Carvalho Chehab
2026-01-28 22:04 ` Jacob Keller
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 24/25] docs: kdoc_parser: better handle struct_group macros Mauro Carvalho Chehab
2026-01-28 17:49 ` Loktionov, Aleksandr
2026-01-28 16:50 ` [Intel-wired-lan] [PATCH v2 25/25] docs: kdoc_re: fix a parse bug on struct page_pool_params Mauro Carvalho Chehab
2026-01-28 17:49 ` Loktionov, Aleksandr
2026-01-28 17:27 ` [Intel-wired-lan] [PATCH v2 00/25] kernel-doc: make it parse new functions and structs Jonathan Corbet
2026-01-28 18:15 ` Jacob Keller
2026-01-28 22:00 ` Mauro Carvalho Chehab
2026-01-28 22:08 ` Jacob Keller
2026-01-29 8:14 ` Mauro Carvalho Chehab
2026-02-10 15:27 ` 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=43b1fb838ba73c3efc18ab605b892f531ffbed01.1769617841.git.mchehab+huawei@kernel.org \
--to=mchehab+huawei@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=sfr@canb.auug.org.au \
/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