qapi: Rename QAPIDoc.Section.name to .tag
Since the previous commit, QAPIDoc.Section.name is either None (untagged section) or the section's tag string ('Returns', '@name', ...). Rename it to .tag. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20240216145841.2099240-9-armbru@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
573e2223f9
commit
31c54b92ad
@ -258,11 +258,11 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
|
|||||||
"""Return list of doctree nodes for additional sections"""
|
"""Return list of doctree nodes for additional sections"""
|
||||||
nodelist = []
|
nodelist = []
|
||||||
for section in doc.sections:
|
for section in doc.sections:
|
||||||
if section.name and section.name == 'TODO':
|
if section.tag and section.tag == 'TODO':
|
||||||
# Hide TODO: sections
|
# Hide TODO: sections
|
||||||
continue
|
continue
|
||||||
snode = self._make_section(section.name)
|
snode = self._make_section(section.tag)
|
||||||
if section.name and section.name.startswith('Example'):
|
if section.tag and section.tag.startswith('Example'):
|
||||||
snode += self._nodes_for_example(section.text)
|
snode += self._nodes_for_example(section.text)
|
||||||
else:
|
else:
|
||||||
self._parse_text_into_node(section.text, snode)
|
self._parse_text_into_node(section.text, snode)
|
||||||
|
@ -471,17 +471,17 @@ class QAPIDoc:
|
|||||||
class Section:
|
class Section:
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
def __init__(self, parser: QAPISchemaParser,
|
def __init__(self, parser: QAPISchemaParser,
|
||||||
name: Optional[str] = None):
|
tag: Optional[str] = None):
|
||||||
# section source info, i.e. where it begins
|
# section source info, i.e. where it begins
|
||||||
self.info = parser.info
|
self.info = parser.info
|
||||||
# parser, for error messages about indentation
|
# parser, for error messages about indentation
|
||||||
self._parser = parser
|
self._parser = parser
|
||||||
# section tag, if any ('Returns', '@name', ...)
|
# section tag, if any ('Returns', '@name', ...)
|
||||||
self.name = name
|
self.tag = tag
|
||||||
# section text without tag
|
# section text without tag
|
||||||
self.text = ''
|
self.text = ''
|
||||||
# indentation to strip (None means indeterminate)
|
# indentation to strip (None means indeterminate)
|
||||||
self._indent = None if self.name else 0
|
self._indent = None if self.tag else 0
|
||||||
|
|
||||||
def append(self, line: str) -> None:
|
def append(self, line: str) -> None:
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
@ -504,8 +504,8 @@ class QAPIDoc:
|
|||||||
|
|
||||||
class ArgSection(Section):
|
class ArgSection(Section):
|
||||||
def __init__(self, parser: QAPISchemaParser,
|
def __init__(self, parser: QAPISchemaParser,
|
||||||
name: str):
|
tag: str):
|
||||||
super().__init__(parser, name)
|
super().__init__(parser, tag)
|
||||||
self.member: Optional['QAPISchemaMember'] = None
|
self.member: Optional['QAPISchemaMember'] = None
|
||||||
|
|
||||||
def connect(self, member: 'QAPISchemaMember') -> None:
|
def connect(self, member: 'QAPISchemaMember') -> None:
|
||||||
@ -536,10 +536,10 @@ class QAPIDoc:
|
|||||||
self._section = self.body
|
self._section = self.body
|
||||||
self._append_line = self._append_body_line
|
self._append_line = self._append_body_line
|
||||||
|
|
||||||
def has_section(self, name: str) -> bool:
|
def has_section(self, tag: str) -> bool:
|
||||||
"""Return True if we have a section with this name."""
|
"""Return True if we have a section with this tag."""
|
||||||
for i in self.sections:
|
for i in self.sections:
|
||||||
if i.name == name:
|
if i.tag == tag:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -710,11 +710,11 @@ class QAPIDoc:
|
|||||||
def _start_features_section(self, name: str) -> None:
|
def _start_features_section(self, name: str) -> None:
|
||||||
self._start_symbol_section(self.features, name)
|
self._start_symbol_section(self.features, name)
|
||||||
|
|
||||||
def _start_section(self, name: Optional[str] = None) -> None:
|
def _start_section(self, tag: Optional[str] = None) -> None:
|
||||||
if name in ('Returns', 'Since') and self.has_section(name):
|
if tag in ('Returns', 'Since') and self.has_section(tag):
|
||||||
raise QAPIParseError(self._parser,
|
raise QAPIParseError(self._parser,
|
||||||
"duplicated '%s' section" % name)
|
"duplicated '%s' section" % tag)
|
||||||
new_section = QAPIDoc.Section(self._parser, name)
|
new_section = QAPIDoc.Section(self._parser, tag)
|
||||||
self._switch_section(new_section)
|
self._switch_section(new_section)
|
||||||
self.sections.append(new_section)
|
self.sections.append(new_section)
|
||||||
|
|
||||||
@ -726,10 +726,10 @@ class QAPIDoc:
|
|||||||
if self._section != self.body and not text:
|
if self._section != self.body and not text:
|
||||||
# We do not create anonymous sections unless there is
|
# We do not create anonymous sections unless there is
|
||||||
# something to put in them; this is a parser bug.
|
# something to put in them; this is a parser bug.
|
||||||
assert self._section.name
|
assert self._section.tag
|
||||||
raise QAPISemError(
|
raise QAPISemError(
|
||||||
self._section.info,
|
self._section.info,
|
||||||
"text required after '%s:'" % self._section.name)
|
"text required after '%s:'" % self._section.tag)
|
||||||
|
|
||||||
self._section = new_section
|
self._section = new_section
|
||||||
|
|
||||||
@ -761,7 +761,7 @@ class QAPIDoc:
|
|||||||
def check_expr(self, expr: QAPIExpression) -> None:
|
def check_expr(self, expr: QAPIExpression) -> None:
|
||||||
if 'command' not in expr:
|
if 'command' not in expr:
|
||||||
sec = next((sec for sec in self.sections
|
sec = next((sec for sec in self.sections
|
||||||
if sec.name == 'Returns'),
|
if sec.tag == 'Returns'),
|
||||||
None)
|
None)
|
||||||
if sec:
|
if sec:
|
||||||
raise QAPISemError(sec.info,
|
raise QAPISemError(sec.info,
|
||||||
|
@ -130,7 +130,7 @@ def test_frontend(fname):
|
|||||||
for feat, section in doc.features.items():
|
for feat, section in doc.features.items():
|
||||||
print(' feature=%s\n%s' % (feat, section.text))
|
print(' feature=%s\n%s' % (feat, section.text))
|
||||||
for section in doc.sections:
|
for section in doc.sections:
|
||||||
print(' section=%s\n%s' % (section.name, section.text))
|
print(' section=%s\n%s' % (section.tag, section.text))
|
||||||
|
|
||||||
|
|
||||||
def open_test_result(dir_name, file_name, update):
|
def open_test_result(dir_name, file_name, update):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user