From nobody Sun Oct 5 18:17:26 2025 Received: from ms.lwn.net (ms.lwn.net [45.79.88.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54DDF3D81; Fri, 1 Aug 2025 00:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.79.88.28 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007224; cv=none; b=eAd+FjeUb48gk3wLvRxld2d0tX5DgUgZdxWDi8M6o+W+7Q7mb5+UVChabsAVQ7zbNeDmoNaOS4ukc2A3xrf1wmVhKU5vO/iFrJ7aOQeMTi46Fa4oeFU0KRmTwDUClDWSghcqwqGnBY6xXkACn88HqwHDLMrHQ99HvGPE7VlYT8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754007224; c=relaxed/simple; bh=bEcraGPV3gR6r987wiaDaKSp3nJiNG59kH23+FTy4qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kH8CuPFFeP8awQybEvWoCGVL5RNaMR6LwCOWMrVsmGGVzxWrJI2WP2KAW3+xbiaSmFL+54ZbTvODEwJEks9MnGjd9vOrfJB+MQucv6nw81voZ8d5CadGz4FCRv0nAGxXLsspug5FyOpljl9xHb3DVVrMWffytJqRXbOKo89S3RY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lwn.net; spf=pass smtp.mailfrom=lwn.net; dkim=pass (2048-bit key) header.d=lwn.net header.i=@lwn.net header.b=emE1SCB3; arc=none smtp.client-ip=45.79.88.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lwn.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lwn.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lwn.net header.i=@lwn.net header.b="emE1SCB3" DKIM-Filter: OpenDKIM Filter v2.11.0 ms.lwn.net 4CD5F40AE5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lwn.net; s=20201203; t=1754007216; bh=BMowMrRpgTtdnzeANz/44PHHl5NAaWPnyULE2WLjzW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=emE1SCB3Je0HVXYzD3QL1p5c9SgjuyoubV3LnMmAyeGbdcfHAMcQcu9Q7BlhQnVFs W35Y6sflAxcFqVhRNJv1BmbuT6VIIqSSymahfHws1HjHJ9AtiNdrdRDkJ7juyXecnB e6JV3cc+zGG8xUaXPK/Q00vigjv2y3qEUClqIoez6h2X1LF/IYiUwsrIXF94sEZd+j Im4qr7SEUDQ01/2ySAyzXZmND+nfpxxoI/j9KId2BqXfeUC0f9j2ddihCK9jLu7xGq +MXpLXR2///xWwhprQaRRp0a404TtsZEfwdG7vh0XIwdHah3cLxH33DnJ4iyp3wHOk mhDLNY0RUrmRA== Received: from trenco.lwn.net (unknown [IPv6:2601:280:4600:2da9::1fe]) by ms.lwn.net (Postfix) with ESMTPA id 4CD5F40AE5; Fri, 1 Aug 2025 00:13:36 +0000 (UTC) From: Jonathan Corbet To: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Akira Yokosawa , Jonathan Corbet Subject: [PATCH 03/12] docs: kdoc: backslashectomy in kdoc_parser Date: Thu, 31 Jul 2025 18:13:17 -0600 Message-ID: <20250801001326.924276-4-corbet@lwn.net> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250801001326.924276-1-corbet@lwn.net> References: <20250801001326.924276-1-corbet@lwn.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A lot of the regular expressions in this file have extraneous backslashes that may have been needed in Perl, but aren't helpful here. Take them out to reduce slightly the visual noise. Signed-off-by: Jonathan Corbet --- scripts/lib/kdoc/kdoc_parser.py | 40 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser= .py index 9948ede739a5..e1efa65a3480 100644 --- a/scripts/lib/kdoc/kdoc_parser.py +++ b/scripts/lib/kdoc/kdoc_parser.py @@ -46,7 +46,7 @@ doc_decl =3D doc_com + KernRe(r'(\w+)', cache=3DFalse) known_section_names =3D 'description|context|returns?|notes?|examples?' known_sections =3D KernRe(known_section_names, flags =3D re.I) doc_sect =3D doc_com + \ - KernRe(r'\s*(\@[.\w]+|\@\.\.\.|' + known_section_names + r')\s*:([^:].= *)?$', + KernRe(r'\s*(@[.\w]+|@\.\.\.|' + known_section_names + r')\s*:([^:].*)= ?$', flags=3Dre.I, cache=3DFalse) =20 doc_content =3D doc_com_body + KernRe(r'(.*)', cache=3DFalse) @@ -60,7 +60,7 @@ attribute =3D KernRe(r"__attribute__\s*\(\([a-z0-9,_\*\s\= (\)]*\)\)", export_symbol =3D KernRe(r'^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*',= cache=3DFalse) export_symbol_ns =3D KernRe(r'^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,= \s*"\S+"\)\s*', cache=3DFalse) =20 -type_param =3D KernRe(r"\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=3DFalse) +type_param =3D KernRe(r"@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=3DFalse) =20 # # Tests for the beginning of a kerneldoc block in its various forms. @@ -331,7 +331,7 @@ class KernelDoc: =20 self.entry.anon_struct_union =3D False =20 - param =3D KernRe(r'[\[\)].*').sub('', param, count=3D1) + param =3D KernRe(r'[)[].*').sub('', param, count=3D1) =20 if dtype =3D=3D "" and param.endswith("..."): if KernRe(r'\w\.\.\.$').search(param): @@ -405,7 +405,7 @@ class KernelDoc: =20 for arg in args.split(splitter): # Strip comments - arg =3D KernRe(r'\/\*.*\*\/').sub('', arg) + arg =3D KernRe(r'/\*.*\*/').sub('', arg) =20 # Ignore argument attributes arg =3D KernRe(r'\sPOS0?\s').sub(' ', arg) @@ -428,14 +428,14 @@ class KernelDoc: =20 arg =3D arg.replace('#', ',') =20 - r =3D KernRe(r'[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)') + r =3D KernRe(r'[^(]+\(\*?\s*([\w[\].]*)\s*\)') if r.match(arg): param =3D r.group(1) else: self.emit_msg(ln, f"Invalid param: {arg}") param =3D arg =20 - dtype =3D KernRe(r'([^\(]+\(\*?)\s*' + re.escape(param)).s= ub(r'\1', arg) + dtype =3D KernRe(r'([^(]+\(\*?)\s*' + re.escape(param)).su= b(r'\1', arg) self.push_parameter(ln, decl_type, param, dtype, arg, declaration_name) =20 @@ -443,14 +443,14 @@ class KernelDoc: # Array-of-pointers =20 arg =3D arg.replace('#', ',') - r =3D KernRe(r'[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[= \w]+\s*\]\s*)*\)') + r =3D KernRe(r'[^(]+\(\s*\*\s*([\w[\].]*?)\s*(\s*\[\s*[\w]= +\s*\]\s*)*\)') if r.match(arg): param =3D r.group(1) else: self.emit_msg(ln, f"Invalid param: {arg}") param =3D arg =20 - dtype =3D KernRe(r'([^\(]+\(\*?)\s*' + re.escape(param)).s= ub(r'\1', arg) + dtype =3D KernRe(r'([^(]+\(\*?)\s*' + re.escape(param)).su= b(r'\1', arg) =20 self.push_parameter(ln, decl_type, param, dtype, arg, declaration_name) @@ -637,8 +637,8 @@ class KernelDoc: # it is better to also move those to the NestedMatch logic, # to ensure that parenthesis will be properly matched. =20 - (KernRe(r'__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)', re= .S), r'DECLARE_BITMAP(\1, __ETHTOOL_LINK_MODE_MASK_NBITS)'), - (KernRe(r'DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)', re.S), r= 'DECLARE_BITMAP(\1, PHY_INTERFACE_MODE_MAX)'), + (KernRe(r'__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^)]+)\)', re.= S), r'DECLARE_BITMAP(\1, __ETHTOOL_LINK_MODE_MASK_NBITS)'), + (KernRe(r'DECLARE_PHY_INTERFACE_MASK\s*\(([^)]+)\)', re.S), r'= DECLARE_BITMAP(\1, PHY_INTERFACE_MODE_MAX)'), (KernRe(r'DECLARE_BITMAP\s*\(' + args_pattern + r',\s*' + args= _pattern + r'\)', re.S), r'unsigned long \1[BITS_TO_LONGS(\2)]'), (KernRe(r'DECLARE_HASHTABLE\s*\(' + args_pattern + r',\s*' + a= rgs_pattern + r'\)', re.S), r'unsigned long \1[1 << ((\2) - 1)]'), (KernRe(r'DECLARE_KFIFO\s*\(' + args_pattern + r',\s*' + args_= pattern + r',\s*' + args_pattern + r'\)', re.S), r'\2 *\1'), @@ -700,7 +700,7 @@ class KernelDoc: s_id =3D s_id.strip() =20 newmember +=3D f"{maintype} {s_id}; " - s_id =3D KernRe(r'[:\[].*').sub('', s_id) + s_id =3D KernRe(r'[:[].*').sub('', s_id) s_id =3D KernRe(r'^\s*\**(\S+)\s*').sub(r'\1', s_id) =20 for arg in content.split(';'): @@ -709,7 +709,7 @@ class KernelDoc: if not arg: continue =20 - r =3D KernRe(r'^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)= ') + r =3D KernRe(r'^([^(]+\(\*?\s*)([\w.]*)(\s*\).*)') if r.match(arg): # Pointer-to-function dtype =3D r.group(1) @@ -767,12 +767,12 @@ class KernelDoc: self.check_sections(ln, declaration_name, decl_type) =20 # Adjust declaration for better display - declaration =3D KernRe(r'([\{;])').sub(r'\1\n', declaration) + declaration =3D KernRe(r'([{;])').sub(r'\1\n', declaration) declaration =3D KernRe(r'\}\s+;').sub('};', declaration) =20 # Better handle inlined enums while True: - r =3D KernRe(r'(enum\s+\{[^\}]+),([^\n])') + r =3D KernRe(r'(enum\s+\{[^}]+),([^\n])') if not r.search(declaration): break =20 @@ -969,8 +969,8 @@ class KernelDoc: # - pci_match_device, __copy_to_user (long return type) =20 name =3D r'[a-zA-Z0-9_~:]+' - prototype_end1 =3D r'[^\(]*' - prototype_end2 =3D r'[^\{]*' + prototype_end1 =3D r'[^(]*' + prototype_end2 =3D r'[^{]*' prototype_end =3D fr'\(({prototype_end1}|{prototype_end2})\)' =20 # Besides compiling, Perl qr{[\w\s]+} works as a non-capturing gro= up. @@ -1044,7 +1044,7 @@ class KernelDoc: Stores a typedef inside self.entries array. """ =20 - typedef_type =3D r'((?:\s+[\w\*]+\b){0,7}\s+(?:\w+\b|\*+))\s*' + typedef_type =3D r'((?:\s+[\w*]+\b){0,7}\s+(?:\w+\b|\*+))\s*' typedef_ident =3D r'\*?\s*(\w\S+)\s*' typedef_args =3D r'\s*\((.*)\);' =20 @@ -1265,7 +1265,7 @@ class KernelDoc: self.dump_section() =20 # Look for doc_com + + doc_end: - r =3D KernRe(r'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') + r =3D KernRe(r'\s*\*\s*[a-zA-Z_0-9:.]+\*/') if r.match(line): self.emit_msg(ln, f"suspicious ending line: {line}") =20 @@ -1476,14 +1476,14 @@ class KernelDoc: """Ancillary routine to process a function prototype""" =20 # strip C99-style comments to end of line - line =3D KernRe(r"\/\/.*$", re.S).sub('', line) + line =3D KernRe(r"//.*$", re.S).sub('', line) # # Soak up the line's worth of prototype text, stopping at { or ; i= f present. # if KernRe(r'\s*#\s*define').match(line): self.entry.prototype =3D line elif not line.startswith('#'): # skip other preprocessor stuff - r =3D KernRe(r'([^\{]*)') + r =3D KernRe(r'([^{]*)') if r.match(line): self.entry.prototype +=3D r.group(1) + " " # --=20 2.50.1