[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 18/26] qapi/parser.py: Modify _include() to use parser state
From: |
John Snow |
Subject: |
[PATCH 18/26] qapi/parser.py: Modify _include() to use parser state |
Date: |
Tue, 22 Sep 2020 18:35:17 -0400 |
It doesn't need to take quite so many arguments.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/parser.py | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 5b3a9b5da8..77067b2f5d 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -144,8 +144,7 @@ def _parse(self) -> None:
incl_fname = os.path.join(os.path.dirname(self._fname),
include)
self._add_expr(OrderedDict({'include': incl_fname}), info)
- exprs_include = self._include(include, info, incl_fname,
- self._included)
+ exprs_include = self._include(include, incl_fname)
if exprs_include:
self.exprs.extend(exprs_include.exprs)
self.docs.extend(exprs_include.docs)
@@ -179,26 +178,22 @@ def reject_expr_doc(cls, doc: Optional['QAPIDoc']) ->
None:
"documentation for '%s' is not followed by the definition"
% doc.symbol)
- @classmethod
- def _include(cls,
- include: str,
- info: QAPISourceInfo,
- incl_fname: str,
- previously_included: Set[str]
- ) -> Optional['QAPISchemaParser']:
+ def _include(self, include: str,
+ incl_fname: str) -> Optional['QAPISchemaParser']:
incl_abs_fname = os.path.abspath(incl_fname)
+
# catch inclusion cycle
- inf = info
+ inf = self.info
while inf:
if incl_abs_fname == os.path.abspath(inf.fname):
- raise QAPISemError(info, "inclusion loop for %s" % include)
+ raise QAPISemError(self.info, f"inclusion loop for {include}")
inf = inf.parent
# skip multiple include of the same file
- if incl_abs_fname in previously_included:
+ if incl_abs_fname in self._included:
return None
- return QAPISchemaParser(incl_fname, previously_included, info)
+ return QAPISchemaParser(incl_fname, self._included, self.info)
def accept(self, skip_comment: bool = True) -> None:
"""
--
2.26.2
- [PATCH 08/26] qapi/parser.py: Assert lexer value is a string, (continued)
- [PATCH 08/26] qapi/parser.py: Assert lexer value is a string, John Snow, 2020/09/22
- [PATCH 06/26] qapi/parser.py: raise QAPIParseError during file opening, John Snow, 2020/09/22
- [PATCH 09/26] qapi/parser.py: assert get_expr returns object in outer loop, John Snow, 2020/09/22
- [PATCH 10/26] qapi/parser.py: assert object keys are strings, John Snow, 2020/09/22
- [PATCH 11/26] qapi/parser.py: Convert several methods to @classmethod, John Snow, 2020/09/22
- [PATCH 12/26] qapi/parser.py: add casts to pragma checks, John Snow, 2020/09/22
- [PATCH 13/26] qapi/parser.py: add type hint annotations, John Snow, 2020/09/22
- [PATCH 14/26] qapi/parser.py: add docstrings, John Snow, 2020/09/22
- [PATCH 15/26] qapi/parser.py: add ParsedExpression type, John Snow, 2020/09/22
- [PATCH 16/26] qapi/pragma.py: Move QAPISchemaPragma into its own module, John Snow, 2020/09/22
- [PATCH 18/26] qapi/parser.py: Modify _include() to use parser state,
John Snow <=
- [PATCH 17/26] qapi/pragma.py: Move pragma parsing out of parser.py, John Snow, 2020/09/22
- [PATCH 20/26] qapi/parser.py: remove unused check_args_section arguments, John Snow, 2020/09/22
- [PATCH 21/26] qapi/parser.py: QAPIDoc: convert @staticmethod to @classmethod, John Snow, 2020/09/22
- [PATCH 19/26] qapi/parser.py: add parent argument, John Snow, 2020/09/22
- [PATCH 23/26] qapi/parser.py: enable mypy checks, John Snow, 2020/09/22
- [PATCH 24/26] qapi/parser.py: remove one and two-letter variables, John Snow, 2020/09/22
- [PATCH 25/26] qapi/parser.py: Silence too-few-public-methods warning, John Snow, 2020/09/22
- [PATCH 26/26] qapi/parser.py: enable pylint checks, John Snow, 2020/09/22
- [PATCH 22/26] qapi/parser.py: add type hint annotations (QAPIDoc), John Snow, 2020/09/22
- Re: [PATCH 00/26] qapi: static typing conversion, pt5, John Snow, 2020/09/22