History

docs: kdoc: split the processing of the two remaining inline states

Now that "inline_*" are just ordinary parser states, split them into two separate functions, getting rid of some nested conditional logic. The original process_inline() would simply ignore lines that didn't match any of the regexes (those lacking the initial " * " marker). I have preserved that behavior, but we should perhaps emit a warning instead.

Jonathan Corbet committed 1 year ago

Commit c7eedb01 parent 096f73a1 file · +18 −19Browse files

Unified · Split

scripts/lib/kdoc/kdoc_parser.py+18−19
@@ -1448,31 +1448,30 @@ class KernelDoc: · 1447 unmodified lines
14481448 # Unknown line, ignore
14491449 self.emit_msg(ln, f"bad line: {line}")
14501450
1451− def process_inline(self, ln, line):
1452− """STATE_INLINE: docbook comments within a prototype."""
1451+ def process_inline_name(self, ln, line):
1452+ """STATE_INLINE_NAME: beginning of docbook comments within a prototype."""
14531453
1454− if self.state == state.INLINE_NAME and \
1455− doc_inline_sect.search(line):
1454+ if doc_inline_sect.search(line):
14561455 self.entry.begin_section(ln, doc_inline_sect.group(1))
1457−
14581456 self.entry.add_text(doc_inline_sect.group(2).lstrip())
14591457 self.state = state.INLINE_TEXT
1460− # Documentation block end */
1461− return
1462−
1463− if doc_inline_end.search(line):
1458+ elif doc_inline_end.search(line):
14641459 self.dump_section()
14651460 self.state = state.PROTO
1466− return
1461+ elif doc_content.search(line):
1462+ self.emit_msg(ln, f"Incorrect use of kernel-doc format: {line}")
1463+ self.state = state.PROTO
1464+ # else ... ??
14671465
1468− if doc_content.search(line):
1469− if self.state == state.INLINE_TEXT:
1470− self.entry.add_text(doc_content.group(1))
1466+ def process_inline_text(self, ln, line):
1467+ """STATE_INLINE_TEXT: docbook comments within a prototype."""
14711468
1472− elif self.state == state.INLINE_NAME:
1473− self.emit_msg(ln,
1474− f"Incorrect use of kernel-doc format: {line}")
1475− self.state = state.PROTO
1469+ if doc_inline_end.search(line):
1470+ self.dump_section()
1471+ self.state = state.PROTO
1472+ elif doc_content.search(line):
1473+ self.entry.add_text(doc_content.group(1))
1474+ # else ... ??
14761475
14771476 def syscall_munge(self, ln, proto): # pylint: disable=W0613
14781477 """
@@ -1699,8 +1698,8 @@ class KernelDoc: · 220 unmodified lines
16991698 state.BODY: process_body,
17001699 state.DECLARATION: process_decl,
17011700 state.SPECIAL_SECTION: process_special,
1702− state.INLINE_NAME: process_inline,
1703− state.INLINE_TEXT: process_inline,
1701+ state.INLINE_NAME: process_inline_name,
1702+ state.INLINE_TEXT: process_inline_text,
17041703 state.PROTO: process_proto,
17051704 state.DOCBLOCK: process_docblock,
17061705 }