From nobody Sun Feb 8 21:11:43 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA00833AD90; Tue, 27 Jan 2026 10:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769508821; cv=none; b=lDYXwzejRDfcT0ACzNCqDrn0k8C+ofFjJB74ynuZUlh9piwBY1jk7zSVWLz5EKQH5qhrY/vBRi16hPElhoWwts14pQ4FUaSCwhQQJNEma+4r131LAOvbYI3vgZlMmidr0wY4+Q1W/fzvC359MZWl7JGwRKzcTJg+DooTb0QUwQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769508821; c=relaxed/simple; bh=tG5aGGSXPFMShMecDATAc+9bVZNzWuT+AaBVlR45Rk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l/E+QNJnJKx9DudBAeJUn1C1jGFeIueAcvzII7lJiY7jW5CU36DC/cdgTcBGScYAmz0zCtSOjbeg4JSScpyvNxqaOtKFLiGMk4NHoxwbjHsKzIXq5tjxW2+sW1n4WL4CgtFo7HmvV3P0vLYq1HQEPi1WnmxJl/stcDodIS3VfwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bkLSFp8w; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bkLSFp8w" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 934A6C19425; Tue, 27 Jan 2026 10:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769508821; bh=tG5aGGSXPFMShMecDATAc+9bVZNzWuT+AaBVlR45Rk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bkLSFp8wGKPaxWg5wD9dgl9JVGg/nlPRKQ9GPi3S837OgDT1JFlg5XvjdPIfRcaLo KZSjpHRN/XA9sBwcXnFDWb640NSe/7n3exfyRmq7FiuP7B1rirZyIaxHApkCM0r1kQ 6qjcD97kPjOGKfZ+2CHUMikEgpGTp4/6AS2xZf4bGUeQrxWFEPTfPVKWt/wYkE3uRP Tb1EXqrguqNpglQO4DnTel/JQPwFhQUfPjIma4OIFJCQRiMf7UwSn7YFOoPTk9ilkW DpvqD2uUIFk0O00VNEow3jMBRvzxyZmY4XdpzayJlLNDbt7mhllWtGUA19vHfg7fWh 5CavfS1CiraYA== Received: from mchehab by mail.kernel.org with local (Exim 4.99.1) (envelope-from ) id 1vkg4p-0000000BVM8-3SFI; Tue, 27 Jan 2026 11:13:39 +0100 From: Mauro Carvalho Chehab To: Jonathan Corbet , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Peter Zijlstra , Randy Dunlap , Stephen Rothwell Subject: [PATCH 05/14] docs: kdoc_parser: add functions support for NestedMatch Date: Tue, 27 Jan 2026 11:13:24 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab 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 Acked-by: Randy Dunlap Tested-by: Randy Dunlap --- tools/lib/python/kdoc/kdoc_parser.py | 39 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/tools/lib/python/kdoc/kdoc_parser.py b/tools/lib/python/kdoc/k= doc_parser.py index 834a527542b3..4b2b0a0d25f8 100644 --- a/tools/lib/python/kdoc/kdoc_parser.py +++ b/tools/lib/python/kdoc/kdoc_parser.py @@ -155,7 +155,7 @@ struct_xforms =3D [ (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. # @@ -163,6 +163,13 @@ struct_nested_prefixes =3D [ (re.compile(r'\bSTRUCT_GROUP\('), r'\1'), ] =20 +# +# Function Regexes here are guaranteed to have the end delimiter matching +# the start delimiter. +# +function_nested_prefixes =3D [ +] + # # Transforms for function prototypes # @@ -206,14 +213,6 @@ var_xforms =3D [ (KernRe(r"=3D.*"), ""), ] =20 -# -# Apply a set of transforms to a block of text. -# -def apply_transforms(xforms, text): - for search, subst in xforms: - text =3D search.sub(subst, text) - return text - # # A little helper to get rid of excess white space # @@ -400,6 +399,8 @@ class KernelDoc: # Place all potential outputs into an array self.entries =3D [] =20 + self.nested =3D NestedMatch() + # # We need Python 3.7 for its "dicts remember the insertion # order" guarantee @@ -497,6 +498,16 @@ class KernelDoc: # State flags self.state =3D state.NORMAL =20 + 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 =3D search.sub(subst, text) + + for search, sub in nested_xforms: + text =3D self.nested.sub(search, sub, text) + + return text.strip() + def push_parameter(self, ln, decl_type, param, dtype, org_arg, declaration_name): """ @@ -865,11 +876,9 @@ class KernelDoc: # Go through the list of members applying all of our transformatio= ns. # members =3D trim_private_members(members) - members =3D apply_transforms(struct_xforms, members) + members =3D self.apply_transforms(struct_xforms, struct_nested_pre= fixes, + members) =20 - nested =3D NestedMatch() - for search, sub in struct_nested_prefixes: - members =3D nested.sub(search, sub, members) # # Deal with embedded struct and union members, and drop enums enti= rely. # @@ -1072,7 +1081,9 @@ class KernelDoc: # # Apply the initial transformations. # - prototype =3D apply_transforms(function_xforms, prototype) + prototype =3D self.apply_transforms(function_xforms, + function_nested_prefixes, + prototype) =20 # Yes, this truly is vile. We are looking for: # 1. Return type (may be nothing if we're looking at a macro) --=20 2.52.0