History

docs: kdoc: finish disentangling the BODY and SPECIAL_SECTION states

Move the last SPECIAL_SECTION special case into the proper handler function, getting rid of more if/then/else logic. The leading-space tracking was tightened up a bit in the move. Add some comments describing what is going on. No changes to the generated output.

Jonathan Corbet committed 1 year ago

Commit 07e04d81 parent ccad65a1 file · +48 −32Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/lib/kdoc/kdoc_parser.py+48−32
@@ -1405,10 +1405,53 @@ class KernelDoc: · 1404 unmodified lines
1405 """1405 """
1406 STATE_SPECIAL_SECTION: a section ending with a blank line1406 STATE_SPECIAL_SECTION: a section ending with a blank line
1407 """1407 """
1408 #
1409 # If we have hit a blank line (only the " * " marker), then this
1410 # section is done.
1411 #
1408 if KernRe(r"\s*\*\s*$").match(line):1412 if KernRe(r"\s*\*\s*$").match(line):
1409 self.entry.begin_section(ln, dump = True)1413 self.entry.begin_section(ln, dump = True)
1414 self.entry.contents += '\n'
1410 self.state = state.BODY1415 self.state = state.BODY
1411 self.process_body(ln, line)1416 return
1417 #
1418 # Not a blank line, look for the other ways to end the section.
1419 #
1420 if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
1421 return
1422 #
1423 # OK, we should have a continuation of the text for this section.
1424 #
1425 if doc_content.search(line):
1426 cont = doc_content.group(1)
1427 #
1428 # If the lines of text after the first in a special section have
1429 # leading white space, we need to trim it out or Sphinx will get
1430 # confused. For the second line (the None case), see what we
1431 # find there and remember it.
1432 #
1433 if self.entry.leading_space is None:
1434 r = KernRe(r'^(\s+)')
1435 if r.match(cont):
1436 self.entry.leading_space = len(r.group(1))
1437 else:
1438 self.entry.leading_space = 0
1439 #
1440 # Otherwise, before trimming any leading chars, be *sure*
1441 # that they are white space. We should maybe warn if this
1442 # isn't the case.
1443 #
1444 for i in range(0, self.entry.leading_space):
1445 if cont[i] != " ":
1446 self.entry.leading_space = i
1447 break
1448 #
1449 # Add the trimmed result to the section and we're done.
1450 #
1451 self.entry.contents += cont[self.entry.leading_space:] + '\n'
1452 else:
1453 # Unknown line, ignore
1454 self.emit_msg(ln, f"bad line: {line}")
1412 1455
1413 def process_body(self, ln, line):1456 def process_body(self, ln, line):
1414 """1457 """
@@ -1419,37 +1462,10 @@ class KernelDoc: · 4 unmodified lines
1419 1462
1420 if doc_content.search(line):1463 if doc_content.search(line):
1421 cont = doc_content.group(1)1464 cont = doc_content.group(1)
1422 1465 self.entry.contents += cont + "\n"
1423 if cont == "":1466 else:
1424 self.entry.contents += "\n"1467 # Unknown line, ignore
1425 else:1468 self.emit_msg(ln, f"bad line: {line}")
1426 if self.state == state.SPECIAL_SECTION:
1427 if self.entry.leading_space is None:
1428 r = KernRe(r'^(\s+)')
1429 if r.match(cont):
1430 self.entry.leading_space = len(r.group(1))
1431 else:
1432 self.entry.leading_space = 0
1433
1434 # Double-check if leading space are realy spaces
1435 pos = 0
1436 for i in range(0, self.entry.leading_space):
1437 if cont[i] != " ":
1438 break
1439 pos += 1
1440
1441 cont = cont[pos:]
1442
1443 # NEW LOGIC:
1444 # In case it is different, update it
1445 if self.entry.leading_space != pos:
1446 self.entry.leading_space = pos
1447
1448 self.entry.contents += cont + "\n"
1449 return
1450
1451 # Unknown line, ignore
1452 self.emit_msg(ln, f"bad line: {line}")
1453 1469
1454 def process_inline(self, ln, line):1470 def process_inline(self, ln, line):
1455 """STATE_INLINE: docbook comments within a prototype."""1471 """STATE_INLINE: docbook comments within a prototype."""

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t