self.exprs: List[QAPIExpression] = []
self.docs: List[QAPIDoc] = []
+ # State for tracking qmp-example blocks and simple
+ # :: literal blocks.
+ self._literal_mode = False
+ self._literal_mode_indent = 0
+
# Showtime!
self._parse()
if self.val != '##':
raise QAPIParseError(
self, "junk after '##' at end of documentation comment")
+ self._literal_mode = False
return None
if self.val == '#':
return ''
if self.val[1] != ' ':
raise QAPIParseError(self, "missing space after #")
- return self.val[2:].rstrip()
+
+ line = self.val[2:].rstrip()
+
+ if re.match(r'(\.\. +qmp-example)? *::$', line):
+ self._literal_mode = True
+ self._literal_mode_indent = 0
+ elif self._literal_mode and line:
+ indent = re.match(r'^ *', line).end()
+ if self._literal_mode_indent == 0:
+ self._literal_mode_indent = indent
+ elif indent < self._literal_mode_indent:
+ # ReST directives stop at decreasing indentation
+ self._literal_mode = False
+
+ if not self._literal_mode:
+ self._validate_doc_line_format(line)
+
+ return line
+
+ def _validate_doc_line_format(self, line: str) -> None:
+ """
+ Validate documentation format rules for a single line:
+ 1. Lines should not exceed 70 characters
+ 2. Sentences should be separated by two spaces
+ """
+ full_line_length = len(line) + 2 # "# " = 2 characters
+ if full_line_length > 70:
+ # Skip URL lines - they can't be broken
+ if re.match(r' *(https?|ftp)://[^ ]*$', line):
+ pass
+ else:
+ raise QAPIParseError(
+ self, "documentation line longer than 70 characters")
+
+ single_space_pattern = r'(\be\.g\.|^ *\d\.|([.!?])) [A-Z0-9(]'
+ for m in list(re.finditer(single_space_pattern, line)):
+ if not m.group(2):
+ continue
+ # HACK so the error message points to the offending spot
+ self.pos = self.line_pos + 2 + m.start(2) + 1
+ raise QAPIParseError(
+ self, "Use two spaces between sentences\n"
+ "If this not the end of a sentence, please report a bug.")
@staticmethod
def _match_at_name_colon(string: str) -> Optional[Match[str]]:
'doc-bad-event-arg.json',
'doc-bad-feature.json',
'doc-bad-indent.json',
+ 'doc-bad-space-between-sentences.json',
'doc-bad-symbol.json',
'doc-bad-union-member.json',
'doc-before-include.json',
'doc-invalid-return2.json',
'doc-invalid-section.json',
'doc-invalid-start.json',
+ 'doc-long-line.json',
'doc-missing-colon.json',
'doc-missing-expr.json',
'doc-missing-space.json',