From: Jonathan Corbet <corbet@lwn.net>
To: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
Jonathan Corbet <corbet@lwn.net>
Subject: [PATCH 8/9] docs: kdoc: move the declaration regexes out of process_name()
Date: Fri, 6 Jun 2025 10:34:37 -0600 [thread overview]
Message-ID: <20250606163438.229916-9-corbet@lwn.net> (raw)
In-Reply-To: <20250606163438.229916-1-corbet@lwn.net>
Move two complex regexes up with the other patterns, decluttering this
function and allowing the compilation to be done once rather than for every
kerneldoc comment.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
scripts/lib/kdoc/kdoc_parser.py | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index 4e1ab28ff7cc..55f38240d4e5 100644
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -47,7 +47,6 @@ doc_sect = doc_com + \
flags=re.I, cache=False)
doc_content = doc_com_body + KernRe(r'(.*)', cache=False)
-doc_block = doc_com + KernRe(r'DOC:\s*(.*)?', cache=False)
doc_inline_start = KernRe(r'^\s*/\*\*\s*$', cache=False)
doc_inline_sect = KernRe(r'\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)', cache=False)
doc_inline_end = KernRe(r'^\s*\*/\s*$', cache=False)
@@ -60,6 +59,18 @@ export_symbol_ns = KernRe(r'^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*"\S+"
type_param = KernRe(r"\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=False)
+#
+# Tests for the beginning of a kerneldoc block in its various forms.
+#
+doc_block = doc_com + KernRe(r'DOC:\s*(.*)?', cache=False)
+doc_begin_data = KernRe(r"^\s*\*?\s*(struct|union|enum|typedef)\b\s*(\w*)", cache = False)
+doc_begin_func = KernRe(str(doc_com) + # initial " * '
+ r"(?:\w+\s*\*\s*)?" + # type (not captured)
+ r'(?:define\s+)?' + # possible "define" (not captured)
+ r'(\w+)\s*(?:\(\w*\))?\s*' + # name and optional "(...)"
+ r'(?:[-:].*)?$', # description (not captured)
+ cache = False)
+
#
# A little helper to get rid of excess white space
#
@@ -1224,22 +1235,15 @@ class KernelDoc:
if doc_decl.search(line):
self.entry.identifier = doc_decl.group(1)
- decl_start = str(doc_com) # comment block asterisk
- fn_type = r"(?:\w+\s*\*\s*)?" # type (for non-functions)
- parenthesis = r"(?:\(\w*\))?" # optional parenthesis on function
- decl_end = r"(?:[-:].*)" # end of the name part
-
# Test for data declaration
- r = KernRe(r"^\s*\*?\s*(struct|union|enum|typedef)\b\s*(\w*)")
- r2 = KernRe(fr"^{decl_start}{fn_type}(?:define\s+)?(\w+)\s*{parenthesis}\s*{decl_end}?$")
- if r.search(line):
- self.entry.decl_type = r.group(1)
- self.entry.identifier = r.group(2)
+ if doc_begin_data.search(line):
+ self.entry.decl_type = doc_begin_data.group(1)
+ self.entry.identifier = doc_begin_data.group(2)
#
# Look for a function description
#
- elif r2.search(line):
- self.entry.identifier = r2.group(1)
+ elif doc_begin_func.search(line):
+ self.entry.identifier = doc_begin_func.group(1)
self.entry.decl_type = "function"
#
# We struck out.
--
2.49.0
next prev parent reply other threads:[~2025-06-06 16:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-06 16:34 [PATCH 0/9] A series of kernel-doc tweaks Jonathan Corbet
2025-06-06 16:34 ` [PATCH 1/9] docs: kdoc: simplify the PROTO continuation logic Jonathan Corbet
2025-06-07 9:59 ` Mauro Carvalho Chehab
2025-06-06 16:34 ` [PATCH 2/9] docs: kdoc: move the core dispatch into a state table Jonathan Corbet
2025-06-07 10:00 ` Mauro Carvalho Chehab
2025-06-06 16:34 ` [PATCH 3/9] docs: kdoc: remove the section_intro variable Jonathan Corbet
2025-06-07 10:03 ` Mauro Carvalho Chehab
2025-06-06 16:34 ` [PATCH 4/9] docs: kdoc: simplify the kerneldoc recognition code Jonathan Corbet
2025-06-07 10:05 ` Mauro Carvalho Chehab
2025-06-06 16:34 ` [PATCH 5/9] docs: kdoc: remove the KernelEntry::is_kernel_comment member Jonathan Corbet
2025-06-07 10:07 ` Mauro Carvalho Chehab
2025-06-07 13:22 ` Jonathan Corbet
2025-06-08 3:18 ` Mauro Carvalho Chehab
2025-06-06 16:34 ` [PATCH 6/9] docs: kdoc: remove the KernelEntry::descr pseudo member Jonathan Corbet
2025-06-07 10:14 ` Mauro Carvalho Chehab
2025-06-06 16:34 ` [PATCH 7/9] docs: kdoc: remove some ineffective code Jonathan Corbet
2025-06-07 10:09 ` Mauro Carvalho Chehab
2025-06-06 16:34 ` Jonathan Corbet [this message]
2025-06-07 10:11 ` [PATCH 8/9] docs: kdoc: move the declaration regexes out of process_name() Mauro Carvalho Chehab
2025-06-06 16:34 ` [PATCH 9/9] docs: kdoc: some final touches for process_name() Jonathan Corbet
2025-06-07 10:13 ` Mauro Carvalho Chehab
2025-06-07 9:58 ` [PATCH 0/9] A series of kernel-doc tweaks 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=20250606163438.229916-9-corbet@lwn.net \
--to=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab+huawei@kernel.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;
as well as URLs for NNTP newsgroup(s).