Skip to content

Commit e7e5403

Browse files
author
Jonathan Corbet
committed
docs: kdoc: don't reinvent string.strip()
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. Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Tested-by: Akira Yokosawa <akiyks@gmail.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/20250703184403.274408-2-corbet@lwn.net
1 parent 38d573a commit e7e5403

1 file changed

Lines changed: 5 additions & 22 deletions

File tree

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,17 +1567,9 @@ def process_proto_function(self, ln, line):
15671567
self.entry.prototype += r.group(1) + " "
15681568

15691569
if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line):
1570-
# strip comments
1571-
r = KernRe(r'/\*.*?\*/')
1572-
self.entry.prototype = r.sub('', self.entry.prototype)
1573-
1574-
# strip newlines/cr's
1575-
r = KernRe(r'[\r\n]+')
1576-
self.entry.prototype = r.sub(' ', self.entry.prototype)
1577-
1578-
# strip leading spaces
1579-
r = KernRe(r'^\s+')
1580-
self.entry.prototype = r.sub('', self.entry.prototype)
1570+
# strip comments and surrounding spaces
1571+
r = KernRe(r'/\*.*\*/')
1572+
self.entry.prototype = r.sub('', self.entry.prototype).strip()
15811573

15821574
# Handle self.entry.prototypes for function pointers like:
15831575
# int (*pcs_config)(struct foo)
@@ -1600,17 +1592,8 @@ def process_proto_function(self, ln, line):
16001592
def process_proto_type(self, ln, line):
16011593
"""Ancillary routine to process a type"""
16021594

1603-
# Strip newlines/cr's.
1604-
line = KernRe(r'[\r\n]+', re.S).sub(' ', line)
1605-
1606-
# Strip leading spaces
1607-
line = KernRe(r'^\s+', re.S).sub('', line)
1608-
1609-
# Strip trailing spaces
1610-
line = KernRe(r'\s+$', re.S).sub('', line)
1611-
1612-
# Strip C99-style comments to the end of the line
1613-
line = KernRe(r"\/\/.*$", re.S).sub('', line)
1595+
# Strip C99-style comments and surrounding whitespace
1596+
line = KernRe(r"//.*$", re.S).sub('', line).strip()
16141597

16151598
# To distinguish preprocessor directive from regular declaration later.
16161599
if line.startswith('#'):

0 commit comments

Comments
 (0)