qapi: Rename QAPIDoc.parser, .section to ._parser, ._section
Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20171002141341.24616-11-armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
76eb6b60ed
commit
8cbf1a537a
|
@ -120,11 +120,11 @@ class QAPIDoc(object):
|
||||||
self.member = member
|
self.member = member
|
||||||
|
|
||||||
def __init__(self, parser, info):
|
def __init__(self, parser, info):
|
||||||
# self.parser is used to report errors with QAPIParseError. The
|
# self._parser is used to report errors with QAPIParseError. The
|
||||||
# resulting error position depends on the state of the parser.
|
# resulting error position depends on the state of the parser.
|
||||||
# It happens to be the beginning of the comment. More or less
|
# It happens to be the beginning of the comment. More or less
|
||||||
# servicable, but action at a distance.
|
# servicable, but action at a distance.
|
||||||
self.parser = parser
|
self._parser = parser
|
||||||
self.info = info
|
self.info = info
|
||||||
self.symbol = None
|
self.symbol = None
|
||||||
self.body = QAPIDoc.Section()
|
self.body = QAPIDoc.Section()
|
||||||
|
@ -133,7 +133,7 @@ class QAPIDoc(object):
|
||||||
# a list of Section
|
# a list of Section
|
||||||
self.sections = []
|
self.sections = []
|
||||||
# the current section
|
# the current section
|
||||||
self.section = self.body
|
self._section = self.body
|
||||||
|
|
||||||
def has_section(self, name):
|
def has_section(self, name):
|
||||||
"""Return True if we have a section with this name."""
|
"""Return True if we have a section with this name."""
|
||||||
|
@ -150,7 +150,7 @@ class QAPIDoc(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if line[0] != ' ':
|
if line[0] != ' ':
|
||||||
raise QAPIParseError(self.parser, "Missing space after #")
|
raise QAPIParseError(self._parser, "Missing space after #")
|
||||||
line = line[1:]
|
line = line[1:]
|
||||||
|
|
||||||
# FIXME not nice: things like '# @foo:' and '# @foo: ' aren't
|
# FIXME not nice: things like '# @foo:' and '# @foo: ' aren't
|
||||||
|
@ -159,11 +159,11 @@ class QAPIDoc(object):
|
||||||
self._append_symbol_line(line)
|
self._append_symbol_line(line)
|
||||||
elif not self.body.text and line.startswith('@'):
|
elif not self.body.text and line.startswith('@'):
|
||||||
if not line.endswith(':'):
|
if not line.endswith(':'):
|
||||||
raise QAPIParseError(self.parser, "Line should end with :")
|
raise QAPIParseError(self._parser, "Line should end with :")
|
||||||
self.symbol = line[1:-1]
|
self.symbol = line[1:-1]
|
||||||
# FIXME invalid names other than the empty string aren't flagged
|
# FIXME invalid names other than the empty string aren't flagged
|
||||||
if not self.symbol:
|
if not self.symbol:
|
||||||
raise QAPIParseError(self.parser, "Invalid name")
|
raise QAPIParseError(self._parser, "Invalid name")
|
||||||
else:
|
else:
|
||||||
self._append_freeform(line)
|
self._append_freeform(line)
|
||||||
|
|
||||||
|
@ -189,48 +189,48 @@ class QAPIDoc(object):
|
||||||
def _start_args_section(self, name):
|
def _start_args_section(self, name):
|
||||||
# FIXME invalid names other than the empty string aren't flagged
|
# FIXME invalid names other than the empty string aren't flagged
|
||||||
if not name:
|
if not name:
|
||||||
raise QAPIParseError(self.parser, "Invalid parameter name")
|
raise QAPIParseError(self._parser, "Invalid parameter name")
|
||||||
if name in self.args:
|
if name in self.args:
|
||||||
raise QAPIParseError(self.parser,
|
raise QAPIParseError(self._parser,
|
||||||
"'%s' parameter name duplicated" % name)
|
"'%s' parameter name duplicated" % name)
|
||||||
if self.sections:
|
if self.sections:
|
||||||
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._end_section()
|
||||||
self.section = QAPIDoc.ArgSection(name)
|
self._section = QAPIDoc.ArgSection(name)
|
||||||
self.args[name] = self.section
|
self.args[name] = self._section
|
||||||
|
|
||||||
def _start_section(self, name=None):
|
def _start_section(self, name=None):
|
||||||
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._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):
|
def _end_section(self):
|
||||||
if self.section:
|
if self._section:
|
||||||
text = self.section.text = self.section.text.strip()
|
text = self._section.text = self._section.text.strip()
|
||||||
if self.section.name and (not text or text.isspace()):
|
if self._section.name and (not text or text.isspace()):
|
||||||
raise QAPIParseError(self.parser, "Empty doc section '%s'"
|
raise QAPIParseError(self._parser, "Empty doc section '%s'"
|
||||||
% self.section.name)
|
% self._section.name)
|
||||||
self.section = None
|
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.text.endswith('\n\n')
|
if (in_arg and self._section.text.endswith('\n\n')
|
||||||
and line and not line[0].isspace()):
|
and line and not line[0].isspace()):
|
||||||
self._start_section()
|
self._start_section()
|
||||||
if (in_arg or not self.section.name
|
if (in_arg or not self._section.name
|
||||||
or not self.section.name.startswith('Example')):
|
or not self._section.name.startswith('Example')):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
match = re.match(r'(@\S+:)', line)
|
match = re.match(r'(@\S+:)', line)
|
||||||
if match:
|
if match:
|
||||||
raise QAPIParseError(self.parser,
|
raise QAPIParseError(self._parser,
|
||||||
"'%s' not allowed in free-form documentation"
|
"'%s' not allowed in free-form documentation"
|
||||||
% match.group(1))
|
% match.group(1))
|
||||||
self.section.append(line)
|
self._section.append(line)
|
||||||
|
|
||||||
def connect_member(self, member):
|
def connect_member(self, member):
|
||||||
if member.name not in self.args:
|
if member.name not in self.args:
|
||||||
|
|
Loading…
Reference in New Issue