[PATCH 8/9] docs: kdoc: Add some comments to process_decl()

Jonathan Corbet posted 9 patches 3 months, 2 weeks ago
[PATCH 8/9] docs: kdoc: Add some comments to process_decl()
Posted by Jonathan Corbet 3 months, 2 weeks ago
Now that the function can actually fit into a human brain, add a few
comments.  While I was at it, I switched to the trim_whitespace() helper
rather than open-coding it.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
 scripts/lib/kdoc/kdoc_parser.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index f7a5b85a8ed7..a6ee8bac378d 100644
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -1377,26 +1377,28 @@ class KernelDoc:
         """
         if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
             return
-
+        #
+        # Look for anything with the " * " line beginning.
+        #
         if doc_content.search(line):
             cont = doc_content.group(1)
-
+            #
+            # A blank line means that we have moved out of the declaration
+            # part of the comment (without any "special section" parameter
+            # descriptions).
+            #
             if cont == "":
                 self.state = state.BODY
                 self.entry.contents += "\n"  # needed?
-
+            #
+            # Otherwise we have more of the declaration section to soak up.
+            #
             else:
-                # Continued declaration purpose
-                self.entry.declaration_purpose = self.entry.declaration_purpose.rstrip()
-                self.entry.declaration_purpose += " " + cont
-
-                r = KernRe(r"\s+")
-                self.entry.declaration_purpose = r.sub(' ',
-                                                       self.entry.declaration_purpose)
-            return
-
-        # Unknown line, ignore
-        self.emit_msg(ln, f"bad line: {line}")
+                self.entry.declaration_purpose = \
+                    trim_whitespace(self.entry.declaration_purpose + ' ' + cont)
+        else:
+            # Unknown line, ignore
+            self.emit_msg(ln, f"bad line: {line}")
 
 
     def process_special(self, ln, line):
-- 
2.49.0
Re: [PATCH 8/9] docs: kdoc: Add some comments to process_decl()
Posted by Mauro Carvalho Chehab 3 months, 2 weeks ago
Em Sat, 21 Jun 2025 14:35:11 -0600
Jonathan Corbet <corbet@lwn.net> escreveu:

> Now that the function can actually fit into a human brain, add a few
> comments.  While I was at it, I switched to the trim_whitespace() helper
> rather than open-coding it.
> 
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>

LGTM.
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

> ---
>  scripts/lib/kdoc/kdoc_parser.py | 30 ++++++++++++++++--------------
>  1 file changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
> index f7a5b85a8ed7..a6ee8bac378d 100644
> --- a/scripts/lib/kdoc/kdoc_parser.py
> +++ b/scripts/lib/kdoc/kdoc_parser.py
> @@ -1377,26 +1377,28 @@ class KernelDoc:
>          """
>          if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
>              return
> -
> +        #
> +        # Look for anything with the " * " line beginning.
> +        #
>          if doc_content.search(line):
>              cont = doc_content.group(1)
> -
> +            #
> +            # A blank line means that we have moved out of the declaration
> +            # part of the comment (without any "special section" parameter
> +            # descriptions).
> +            #
>              if cont == "":
>                  self.state = state.BODY
>                  self.entry.contents += "\n"  # needed?
> -
> +            #
> +            # Otherwise we have more of the declaration section to soak up.
> +            #
>              else:
> -                # Continued declaration purpose
> -                self.entry.declaration_purpose = self.entry.declaration_purpose.rstrip()
> -                self.entry.declaration_purpose += " " + cont
> -
> -                r = KernRe(r"\s+")
> -                self.entry.declaration_purpose = r.sub(' ',
> -                                                       self.entry.declaration_purpose)
> -            return
> -
> -        # Unknown line, ignore
> -        self.emit_msg(ln, f"bad line: {line}")
> +                self.entry.declaration_purpose = \
> +                    trim_whitespace(self.entry.declaration_purpose + ' ' + cont)
> +        else:
> +            # Unknown line, ignore
> +            self.emit_msg(ln, f"bad line: {line}")
>  
>  
>      def process_special(self, ln, line):



Thanks,
Mauro