Skip to content

Commit b0b8891

Browse files
mchehabJonathan Corbet
authored andcommitted
docs: kdoc_re: Improve docstrings and comments
In preparation to document kernel-doc module, improve its documentation. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Message-ID: <14a12a43144d52345bfd405d0401d246f0885acf.1768838938.git.mchehab+huawei@kernel.org>
1 parent 245f1ab commit b0b8891

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

tools/lib/python/kdoc/kdoc_re.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def __str__(self):
5151
"""
5252
return self.regex.pattern
5353

54+
def __repr__(self):
55+
return f're.compile("{self.regex.pattern}")'
56+
5457
def __add__(self, other):
5558
"""
5659
Allows adding two regular expressions into one.
@@ -61,44 +64,44 @@ def __add__(self, other):
6164

6265
def match(self, string):
6366
"""
64-
Handles a re.match storing its results
67+
Handles a re.match storing its results.
6568
"""
6669

6770
self.last_match = self.regex.match(string)
6871
return self.last_match
6972

7073
def search(self, string):
7174
"""
72-
Handles a re.search storing its results
75+
Handles a re.search storing its results.
7376
"""
7477

7578
self.last_match = self.regex.search(string)
7679
return self.last_match
7780

7881
def findall(self, string):
7982
"""
80-
Alias to re.findall
83+
Alias to re.findall.
8184
"""
8285

8386
return self.regex.findall(string)
8487

8588
def split(self, string):
8689
"""
87-
Alias to re.split
90+
Alias to re.split.
8891
"""
8992

9093
return self.regex.split(string)
9194

9295
def sub(self, sub, string, count=0):
9396
"""
94-
Alias to re.sub
97+
Alias to re.sub.
9598
"""
9699

97100
return self.regex.sub(sub, string, count=count)
98101

99102
def group(self, num):
100103
"""
101-
Returns the group results of the last match
104+
Returns the group results of the last match.
102105
"""
103106

104107
return self.last_match.group(num)
@@ -110,7 +113,7 @@ class NestedMatch:
110113
even harder on Python with its normal re module, as there are several
111114
advanced regular expressions that are missing.
112115
113-
This is the case of this pattern:
116+
This is the case of this pattern::
114117
115118
'\\bSTRUCT_GROUP(\\(((?:(?>[^)(]+)|(?1))*)\\))[^;]*;'
116119
@@ -121,6 +124,7 @@ class NestedMatch:
121124
replace nested expressions.
122125
123126
The original approach was suggested by:
127+
124128
https://stackoverflow.com/questions/5454322/python-how-to-match-nested-parentheses-with-regex
125129
126130
Although I re-implemented it to make it more generic and match 3 types

0 commit comments

Comments
 (0)