diff options
author | John Snow <jsnow@redhat.com> | 2021-04-21 15:22:30 -0400 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2021-04-30 12:59:54 +0200 |
commit | ac6a7d8884762d27cc2dde5a5c6e793cc18fc4d9 (patch) | |
tree | f7f114c5aa4f3386b389f2f5651eaaa31502c8c0 | |
parent | ac89761179ed6e3165a63ad68759f77f33bace30 (diff) | |
download | qemu-ac6a7d8884762d27cc2dde5a5c6e793cc18fc4d9.zip qemu-ac6a7d8884762d27cc2dde5a5c6e793cc18fc4d9.tar.gz qemu-ac6a7d8884762d27cc2dde5a5c6e793cc18fc4d9.tar.bz2 |
qapi/error.py: move QAPIParseError to parser.py
Keeping it in error.py will create some cyclic import problems when we
add types to the QAPISchemaParser. Callers don't need to know the
details of QAPIParseError unless they are parsing or dealing directly
with the parser, so this won't create any harsh new requirements for
callers in the general case.
Update error.py with a little docstring that gives a nod to where the
error may now be found.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210421192233.3542904-6-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
-rw-r--r-- | scripts/qapi/error.py | 22 | ||||
-rw-r--r-- | scripts/qapi/parser.py | 14 |
2 files changed, 21 insertions, 15 deletions
diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index d0bc7af..6723c5a 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- # -# QAPI error classes -# # Copyright (c) 2017-2019 Red Hat Inc. # # Authors: @@ -11,6 +9,14 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. +""" +QAPI error classes + +Common error classes used throughout the package. Additional errors may +be defined in other modules. At present, `QAPIParseError` is defined in +parser.py. +""" + class QAPIError(Exception): """Base class for all exceptions from the QAPI package.""" @@ -33,17 +39,5 @@ class QAPISourceError(QAPIError): return loc + ': ' + self.msg -class QAPIParseError(QAPISourceError): - """Error class for all QAPI schema parsing errors.""" - def __init__(self, parser, msg): - col = 1 - for ch in parser.src[parser.line_pos:parser.pos]: - if ch == '\t': - col = (col + 7) % 8 + 1 - else: - col += 1 - super().__init__(parser.info, msg, col) - - class QAPISemError(QAPISourceError): """Error class for semantic QAPI errors.""" diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 58267c3..ca5e8e1 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -18,10 +18,22 @@ from collections import OrderedDict import os import re -from .error import QAPIParseError, QAPISemError +from .error import QAPISemError, QAPISourceError from .source import QAPISourceInfo +class QAPIParseError(QAPISourceError): + """Error class for all QAPI schema parsing errors.""" + def __init__(self, parser, msg): + col = 1 + for ch in parser.src[parser.line_pos:parser.pos]: + if ch == '\t': + col = (col + 7) % 8 + 1 + else: + col += 1 + super().__init__(parser.info, msg, col) + + class QAPISchemaParser: def __init__(self, fname, previously_included=None, incl_info=None): |