From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Akira Yokosawa <akiyks@gmail.com>
Subject: Re: [PATCH 9/9] docs: kdoc: finish disentangling the BODY and SPECIAL_SECTION states
Date: Sun, 22 Jun 2025 13:54:54 +0200 [thread overview]
Message-ID: <20250622135454.41fa0c7c@foz.lan> (raw)
In-Reply-To: <20250621203512.223189-10-corbet@lwn.net>
Em Sat, 21 Jun 2025 14:35:12 -0600
Jonathan Corbet <corbet@lwn.net> escreveu:
> Move the last SPECIAL_SECTION special case into the proper handler
> function, getting rid of more if/then/else logic. The leading-space
> tracking was tightened up a bit in the move. Add some comments describing
> what is going on.
>
> No changes to the generated output.
LGTM.
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
> ---
> scripts/lib/kdoc/kdoc_parser.py | 80 ++++++++++++++++++++-------------
> 1 file changed, 48 insertions(+), 32 deletions(-)
>
> diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
> index a6ee8bac378d..3557c512c85a 100644
> --- a/scripts/lib/kdoc/kdoc_parser.py
> +++ b/scripts/lib/kdoc/kdoc_parser.py
> @@ -1405,10 +1405,53 @@ class KernelDoc:
> """
> STATE_SPECIAL_SECTION: a section ending with a blank line
> """
> + #
> + # If we have hit a blank line (only the " * " marker), then this
> + # section is done.
> + #
> if KernRe(r"\s*\*\s*$").match(line):
> self.entry.begin_section(ln, dump = True)
> + self.entry.contents += '\n'
> self.state = state.BODY
> - self.process_body(ln, line)
> + return
> + #
> + # Not a blank line, look for the other ways to end the section.
> + #
> + if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
> + return
> + #
> + # OK, we should have a continuation of the text for this section.
> + #
> + if doc_content.search(line):
> + cont = doc_content.group(1)
> + #
> + # If the lines of text after the first in a special section have
> + # leading white space, we need to trim it out or Sphinx will get
> + # confused. For the second line (the None case), see what we
> + # find there and remember it.
> + #
> + if self.entry.leading_space is None:
> + r = KernRe(r'^(\s+)')
> + if r.match(cont):
> + self.entry.leading_space = len(r.group(1))
> + else:
> + self.entry.leading_space = 0
> + #
> + # Otherwise, before trimming any leading chars, be *sure*
> + # that they are white space. We should maybe warn if this
> + # isn't the case.
> + #
> + for i in range(0, self.entry.leading_space):
> + if cont[i] != " ":
> + self.entry.leading_space = i
> + break
> + #
> + # Add the trimmed result to the section and we're done.
> + #
> + self.entry.contents += cont[self.entry.leading_space:] + '\n'
> + else:
> + # Unknown line, ignore
> + self.emit_msg(ln, f"bad line: {line}")
>
> def process_body(self, ln, line):
> """
> @@ -1419,37 +1462,10 @@ class KernelDoc:
>
> if doc_content.search(line):
> cont = doc_content.group(1)
> -
> - if cont == "":
> - self.entry.contents += "\n"
> - else:
> - if self.state == state.SPECIAL_SECTION:
> - if self.entry.leading_space is None:
> - r = KernRe(r'^(\s+)')
> - if r.match(cont):
> - self.entry.leading_space = len(r.group(1))
> - else:
> - self.entry.leading_space = 0
> -
> - # Double-check if leading space are realy spaces
> - pos = 0
> - for i in range(0, self.entry.leading_space):
> - if cont[i] != " ":
> - break
> - pos += 1
> -
> - cont = cont[pos:]
> -
> - # NEW LOGIC:
> - # In case it is different, update it
> - if self.entry.leading_space != pos:
> - self.entry.leading_space = pos
> -
> - self.entry.contents += cont + "\n"
> - return
> -
> - # Unknown line, ignore
> - self.emit_msg(ln, f"bad line: {line}")
> + self.entry.contents += cont + "\n"
> + else:
> + # Unknown line, ignore
> + self.emit_msg(ln, f"bad line: {line}")
>
> def process_inline(self, ln, line):
> """STATE_INLINE: docbook comments within a prototype."""
Thanks,
Mauro
prev parent reply other threads:[~2025-06-22 11:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-21 20:35 [PATCH 0/9] docs: kdoc: rework the BODY* processing states Jonathan Corbet
2025-06-21 20:35 ` [PATCH 1/9] docs: kdoc: Make body_with_blank_line parsing more flexible Jonathan Corbet
2025-06-22 11:46 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 2/9] docs: kdoc: consolidate the "begin section" logic Jonathan Corbet
2025-06-22 11:47 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 3/9] docs: kdoc: separate out the handling of the declaration phase Jonathan Corbet
2025-06-22 11:48 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 4/9] docs: kdoc: split out the special-section state Jonathan Corbet
2025-06-22 11:50 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 5/9] docs: kdoc: coalesce the new-section handling Jonathan Corbet
2025-06-22 11:50 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 6/9] docs: kdoc: rework the handling of SPECIAL_SECTION Jonathan Corbet
2025-06-22 11:51 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 7/9] docs: kdoc: coalesce the end-of-comment processing Jonathan Corbet
2025-06-22 11:52 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 8/9] docs: kdoc: Add some comments to process_decl() Jonathan Corbet
2025-06-22 11:53 ` Mauro Carvalho Chehab
2025-06-21 20:35 ` [PATCH 9/9] docs: kdoc: finish disentangling the BODY and SPECIAL_SECTION states Jonathan Corbet
2025-06-22 11:54 ` Mauro Carvalho Chehab [this message]
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=20250622135454.41fa0c7c@foz.lan \
--to=mchehab+huawei@kernel.org \
--cc=akiyks@gmail.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.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).