mirror of https://github.com/xemu-project/xemu.git
qapi: Move empty doc section checking to doc parser
Results in a more precise error location, but the real reason is emptying out check_docs() step by step. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1489582656-31133-35-git-send-email-armbru@redhat.com>
This commit is contained in:
parent
2d433236df
commit
4ea7148e89
|
@ -173,6 +173,9 @@ class QAPIDoc(object):
|
||||||
else:
|
else:
|
||||||
self._append_freeform(line)
|
self._append_freeform(line)
|
||||||
|
|
||||||
|
def end_comment(self):
|
||||||
|
self._end_section()
|
||||||
|
|
||||||
def _append_symbol_line(self, line):
|
def _append_symbol_line(self, line):
|
||||||
name = line.split(' ', 1)[0]
|
name = line.split(' ', 1)[0]
|
||||||
|
|
||||||
|
@ -200,6 +203,7 @@ class QAPIDoc(object):
|
||||||
raise QAPIParseError(self.parser,
|
raise QAPIParseError(self.parser,
|
||||||
"'@%s:' can't follow '%s' section"
|
"'@%s:' can't follow '%s' section"
|
||||||
% (name, self.sections[0].name))
|
% (name, self.sections[0].name))
|
||||||
|
self._end_section()
|
||||||
self.section = QAPIDoc.ArgSection(name)
|
self.section = QAPIDoc.ArgSection(name)
|
||||||
self.args[name] = self.section
|
self.args[name] = self.section
|
||||||
|
|
||||||
|
@ -207,9 +211,18 @@ class QAPIDoc(object):
|
||||||
if name in ('Returns', 'Since') and self.has_section(name):
|
if name in ('Returns', 'Since') and self.has_section(name):
|
||||||
raise QAPIParseError(self.parser,
|
raise QAPIParseError(self.parser,
|
||||||
"Duplicated '%s' section" % name)
|
"Duplicated '%s' section" % name)
|
||||||
|
self._end_section()
|
||||||
self.section = QAPIDoc.Section(name)
|
self.section = QAPIDoc.Section(name)
|
||||||
self.sections.append(self.section)
|
self.sections.append(self.section)
|
||||||
|
|
||||||
|
def _end_section(self):
|
||||||
|
if self.section:
|
||||||
|
contents = str(self.section)
|
||||||
|
if self.section.name and (not contents or contents.isspace()):
|
||||||
|
raise QAPIParseError(self.parser, "Empty doc section '%s'"
|
||||||
|
% self.section.name)
|
||||||
|
self.section = None
|
||||||
|
|
||||||
def _append_freeform(self, line):
|
def _append_freeform(self, line):
|
||||||
in_arg = isinstance(self.section, QAPIDoc.ArgSection)
|
in_arg = isinstance(self.section, QAPIDoc.ArgSection)
|
||||||
if (in_arg and self.section.content
|
if (in_arg and self.section.content
|
||||||
|
@ -512,6 +525,7 @@ class QAPISchemaParser(object):
|
||||||
if self.val != '##':
|
if self.val != '##':
|
||||||
raise QAPIParseError(self, "Junk after '##' at end of "
|
raise QAPIParseError(self, "Junk after '##' at end of "
|
||||||
"documentation comment")
|
"documentation comment")
|
||||||
|
doc.end_comment()
|
||||||
self.accept()
|
self.accept()
|
||||||
return doc
|
return doc
|
||||||
else:
|
else:
|
||||||
|
@ -1012,12 +1026,6 @@ def check_definition_doc(doc, expr, info):
|
||||||
|
|
||||||
def check_docs(docs):
|
def check_docs(docs):
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
for section in doc.args.values() + doc.sections:
|
|
||||||
content = str(section)
|
|
||||||
if not content or content.isspace():
|
|
||||||
raise QAPISemError(doc.info,
|
|
||||||
"Empty doc section '%s'" % section.name)
|
|
||||||
|
|
||||||
if doc.expr:
|
if doc.expr:
|
||||||
check_definition_doc(doc, doc.expr, doc.info)
|
check_definition_doc(doc, doc.expr, doc.info)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
tests/qapi-schema/doc-empty-section.json:3: Empty doc section 'Note'
|
tests/qapi-schema/doc-empty-section.json:7:1: Empty doc section 'Note'
|
||||||
|
|
Loading…
Reference in New Issue