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 2/9] docs: kdoc: move the core dispatch into a state table
Date: Fri, 6 Jun 2025 10:34:31 -0600 [thread overview]
Message-ID: <20250606163438.229916-3-corbet@lwn.net> (raw)
In-Reply-To: <20250606163438.229916-1-corbet@lwn.net>
Since all of the handlers already nicely have the same prototype, put them
into a table and call them from there and take out the extended
if-then-else series.
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 b193cf9dc0d1..37b7e501af7c 100644
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -1670,6 +1670,21 @@ class KernelDoc:
return export_table
+ #
+ # The state/action table telling us which function to invoke in
+ # each state.
+ #
+ state_actions = {
+ state.NORMAL: process_normal,
+ state.NAME: process_name,
+ state.BODY: process_body,
+ state.BODY_MAYBE: process_body,
+ state.BODY_WITH_BLANK_LINE: process_body,
+ state.INLINE: process_inline,
+ state.PROTO: process_proto,
+ state.DOCBLOCK: process_docblock,
+ }
+
def parse_kdoc(self):
"""
Open and process each line of a C source file.
@@ -1721,19 +1736,8 @@ class KernelDoc:
self.process_export(export_table, line)
# Hand this line to the appropriate state handler
- if self.state == state.NORMAL:
- self.process_normal(ln, line)
- elif self.state == state.NAME:
- self.process_name(ln, line)
- elif self.state in [state.BODY, state.BODY_MAYBE,
- state.BODY_WITH_BLANK_LINE]:
- self.process_body(ln, line)
- elif self.state == state.INLINE: # scanning for inline parameters
- self.process_inline(ln, line)
- elif self.state == state.PROTO:
- self.process_proto(ln, line)
- elif self.state == state.DOCBLOCK:
- self.process_docblock(ln, line)
+ self.state_actions[self.state](self, ln, line)
+
except OSError:
self.config.log.error(f"Error: Cannot open file {self.fname}")
--
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 ` Jonathan Corbet [this message]
2025-06-07 10:00 ` [PATCH 2/9] docs: kdoc: move the core dispatch into a state table 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 ` [PATCH 8/9] docs: kdoc: move the declaration regexes out of process_name() Jonathan Corbet
2025-06-07 10:11 ` 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-3-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).