Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: kdoc: consolidate the "begin section" logic

Pull the repeated "begin a section" logic into a single place and hide it
within the KernelEntry class.

Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20250621203512.223189-3-corbet@lwn.net

+17 -15
+17 -15
scripts/lib/kdoc/kdoc_parser.py
··· 169 169 self.warnings.append(log_msg) 170 170 return 171 171 172 + # 173 + # Begin a new section. 174 + # 175 + def begin_section(self, line_no, title = SECTION_DEFAULT, dump = False): 176 + if dump: 177 + self.dump_section(start_new = True) 178 + self.section = title 179 + self.new_start_line = line_no 180 + 172 181 def dump_section(self, start_new=True): 173 182 """ 174 183 Dumps section contents to arrays/hashes intended for that purpose. ··· 1240 1231 # Check for a DOC: block and handle them specially. 1241 1232 # 1242 1233 if doc_block.search(line): 1243 - self.entry.new_start_line = ln 1244 1234 1245 1235 if not doc_block.group(1): 1246 - self.entry.section = "Introduction" 1236 + self.entry.begin_section(ln, "Introduction") 1247 1237 else: 1248 - self.entry.section = doc_block.group(1) 1238 + self.entry.begin_section(ln, doc_block.group(1)) 1249 1239 1250 1240 self.entry.identifier = self.entry.section 1251 1241 self.state = state.DOCBLOCK ··· 1278 1270 self.state = state.BODY 1279 1271 self.entry.identifier = self.entry.identifier.strip(" ") 1280 1272 # if there's no @param blocks need to set up default section here 1281 - self.entry.section = SECTION_DEFAULT 1282 - self.entry.new_start_line = ln + 1 1273 + self.entry.begin_section(ln + 1) 1283 1274 # 1284 1275 # Find the description portion, which *should* be there but 1285 1276 # isn't always. ··· 1319 1312 r = KernRe(r"\s*\*\s*\S") 1320 1313 if r.match(line): 1321 1314 self.dump_section() 1322 - self.entry.section = SECTION_DEFAULT 1323 - self.entry.new_start_line = ln 1315 + self.entry.begin_section(ln) 1324 1316 self.entry.contents = "" 1325 1317 1326 1318 if doc_sect.search(line): ··· 1346 1340 if self.entry.contents.strip("\n"): 1347 1341 self.dump_section() 1348 1342 1349 - self.entry.new_start_line = ln 1350 - self.entry.section = newsection 1343 + self.entry.begin_section(ln, newsection) 1351 1344 self.entry.leading_space = None 1352 1345 1353 1346 self.entry.contents = newcontents.lstrip() ··· 1375 1370 1376 1371 if cont == "": 1377 1372 if self.entry.section == self.section_context: 1378 - self.dump_section() 1379 - 1380 - self.entry.new_start_line = ln 1373 + self.entry.begin_section(ln, dump = True) 1381 1374 self.state = state.BODY 1382 1375 else: 1383 1376 if self.entry.section != SECTION_DEFAULT: ··· 1430 1427 1431 1428 if self.inline_doc_state == state.INLINE_NAME and \ 1432 1429 doc_inline_sect.search(line): 1433 - self.entry.section = doc_inline_sect.group(1) 1434 - self.entry.new_start_line = ln 1430 + self.entry.begin_section(ln, doc_inline_sect.group(1)) 1435 1431 1436 1432 self.entry.contents = doc_inline_sect.group(2).lstrip() 1437 1433 if self.entry.contents != "": ··· 1629 1627 """STATE_PROTO: reading a function/whatever prototype.""" 1630 1628 1631 1629 if doc_inline_oneline.search(line): 1632 - self.entry.section = doc_inline_oneline.group(1) 1630 + self.entry.begin_section(ln, doc_inline_oneline.group(1)) 1633 1631 self.entry.contents = doc_inline_oneline.group(2) 1634 1632 1635 1633 if self.entry.contents != "":