linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 1/7] docs: kdoc: don't reinvent string.strip()
Date: Thu, 3 Jul 2025 17:43:28 +0200	[thread overview]
Message-ID: <20250703174328.059685e7@sal.lan> (raw)
In-Reply-To: <20250701205730.146687-2-corbet@lwn.net>

Em Tue,  1 Jul 2025 14:57:24 -0600
Jonathan Corbet <corbet@lwn.net> escreveu:

> process_proto_type() and process_proto_function() reinventing the strip()
> string method with a whole series of separate regexes; take all that out
> and just use strip().
> 
> The previous implementation also (in process_proto_type()) removed C++
> comments *after* the above dance, leaving trailing whitespace in that case;
> now we do the stripping afterward.  This results in exactly one output
> change: the removal of a spurious space in the definition of
> BACKLIGHT_POWER_REDUCED - see
> https://docs.kernel.org/gpu/backlight.html#c.backlight_properties.
> 
> I note that we are putting semicolons after #define lines that really
> shouldn't be there - a task for another day.

Perhaps add a FIXME note for us to not forget again about this.

> 
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>

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

> ---
>  scripts/lib/kdoc/kdoc_parser.py | 27 +++++----------------------
>  1 file changed, 5 insertions(+), 22 deletions(-)
> 
> diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
> index 93938155fce2..d9ff2d066160 100644
> --- a/scripts/lib/kdoc/kdoc_parser.py
> +++ b/scripts/lib/kdoc/kdoc_parser.py
> @@ -1567,17 +1567,9 @@ class KernelDoc:
>                  self.entry.prototype += r.group(1) + " "
>  
>          if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line):
> -            # strip comments
> -            r = KernRe(r'/\*.*?\*/')
> -            self.entry.prototype = r.sub('', self.entry.prototype)
> -
> -            # strip newlines/cr's
> -            r = KernRe(r'[\r\n]+')
> -            self.entry.prototype = r.sub(' ', self.entry.prototype)
> -
> -            # strip leading spaces
> -            r = KernRe(r'^\s+')
> -            self.entry.prototype = r.sub('', self.entry.prototype)
> +            # strip comments and surrounding spaces
> +            r = KernRe(r'/\*.*\*/')
> +            self.entry.prototype = r.sub('', self.entry.prototype).strip()
>  
>              # Handle self.entry.prototypes for function pointers like:
>              #       int (*pcs_config)(struct foo)
> @@ -1600,17 +1592,8 @@ class KernelDoc:
>      def process_proto_type(self, ln, line):
>          """Ancillary routine to process a type"""
>  
> -        # Strip newlines/cr's.
> -        line = KernRe(r'[\r\n]+', re.S).sub(' ', line)
> -
> -        # Strip leading spaces
> -        line = KernRe(r'^\s+', re.S).sub('', line)
> -
> -        # Strip trailing spaces
> -        line = KernRe(r'\s+$', re.S).sub('', line)
> -
> -        # Strip C99-style comments to the end of the line
> -        line = KernRe(r"\/\/.*$", re.S).sub('', line)
> +        # Strip C99-style comments and surrounding whitespace
> +        line = KernRe(r"//.*$", re.S).sub('', line).strip()
>  
>          # To distinguish preprocessor directive from regular declaration later.
>          if line.startswith('#'):

  reply	other threads:[~2025-07-03 15:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-01 20:57 [PATCH 0/7] Further kernel-doc tweakery Jonathan Corbet
2025-07-01 20:57 ` [PATCH 1/7] docs: kdoc: don't reinvent string.strip() Jonathan Corbet
2025-07-03 15:43   ` Mauro Carvalho Chehab [this message]
2025-07-01 20:57 ` [PATCH 2/7] docs: kdoc: micro-optimize KernRe Jonathan Corbet
2025-07-03 15:38   ` Mauro Carvalho Chehab
2025-07-03 18:14     ` Jonathan Corbet
2025-07-03 22:27       ` Mauro Carvalho Chehab
2025-07-01 20:57 ` [PATCH 3/7] docs: kdoc: remove the brcount floor in process_proto_type() Jonathan Corbet
2025-07-03 15:39   ` Mauro Carvalho Chehab
2025-07-01 20:57 ` [PATCH 4/7] docs: kdoc: rework type prototype parsing Jonathan Corbet
2025-07-03 15:46   ` Mauro Carvalho Chehab
2025-07-01 20:57 ` [PATCH 5/7] docs: kdoc: some tweaks to process_proto_function() Jonathan Corbet
2025-07-03 15:48   ` Mauro Carvalho Chehab
2025-07-01 20:57 ` [PATCH 6/7] docs: kdoc: Remove a Python 2 comment Jonathan Corbet
2025-07-02  8:23   ` Jani Nikula
2025-07-03 15:49   ` Mauro Carvalho Chehab
2025-07-01 20:57 ` [PATCH 7/7] docs: kdoc: pretty up dump_enum() Jonathan Corbet
2025-07-03 15:57   ` Mauro Carvalho Chehab
2025-07-03 18:17     ` Jonathan Corbet
2025-07-03 22:29       ` Mauro Carvalho Chehab
2025-07-03 15:01 ` [PATCH 0/7] Further kernel-doc tweakery Akira Yokosawa
2025-07-03 18:20   ` Jonathan Corbet

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=20250703174328.059685e7@sal.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).