[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250607120019.20dff0a3@foz.lan>
Date: Sat, 7 Jun 2025 12:00:19 +0200
From: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
To: Jonathan Corbet <corbet@....net>
Cc: linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/9] docs: kdoc: move the core dispatch into a state
table
Em Fri, 6 Jun 2025 10:34:31 -0600
Jonathan Corbet <corbet@....net> escreveu:
> 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@....net>
LGTM.
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
> ---
> 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}")
>
Thanks,
Mauro
Powered by blists - more mailing lists