Skip to content

Commit ff1f2af

Browse files
author
Jonathan Corbet
committed
docs: kdoc: Simplify the dump_function() prototype regexes
The regexes for the parsing of function prototypes were more complicated than they needed to be and difficult to understand -- at least, I spent a fair amount of time bashing my head against them. Simplify them, and add some documentation comments as well. Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 08b5228 commit ff1f2af

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -959,15 +959,15 @@ def dump_function(self, ln, prototype):
959959
# - pci_match_device, __copy_to_user (long return type)
960960

961961
name = r'\w+'
962-
prototype_end1 = r'[^\(]*'
963-
prototype_end2 = r'[^\{]*'
964-
prototype_end = fr'\(({prototype_end1}|{prototype_end2})\)'
965-
966-
# Besides compiling, Perl qr{[\w\s]+} works as a non-capturing group.
967-
# So, this needs to be mapped in Python with (?:...)? or (?:...)+
968-
969962
type1 = r'(?:[\w\s]+)?'
970963
type2 = r'(?:[\w\s]+\*+)+'
964+
#
965+
# Attempt to match first on (args) with no internal parentheses; this
966+
# lets us easily filter out __acquires() and other post-args stuff. If
967+
# that fails, just grab the rest of the line to the last closing
968+
# parenthesis.
969+
#
970+
proto_args = r'\(([^\(]*|.*)\)'
971971

972972
found = False
973973

@@ -983,9 +983,9 @@ def dump_function(self, ln, prototype):
983983

984984
if not found:
985985
patterns = [
986-
rf'^()({name})\s*{prototype_end}',
987-
rf'^({type1})\s+({name})\s*{prototype_end}',
988-
rf'^({type2})\s*({name})\s*{prototype_end}',
986+
rf'^()({name})\s*{proto_args}',
987+
rf'^({type1})\s+({name})\s*{proto_args}',
988+
rf'^({type2})\s*({name})\s*{proto_args}',
989989
]
990990

991991
for p in patterns:

0 commit comments

Comments
 (0)