aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi/parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/qapi/parser.py')
-rw-r--r--scripts/qapi/parser.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 1b006cdc13..878f90b458 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -21,6 +21,7 @@ from typing import (
TYPE_CHECKING,
Dict,
List,
+ Mapping,
Optional,
Set,
Union,
@@ -37,15 +38,19 @@ if TYPE_CHECKING:
from .schema import QAPISchemaFeature, QAPISchemaMember
-#: Represents a single Top Level QAPI schema expression.
-TopLevelExpr = Dict[str, object]
-
# Return value alias for get_expr().
_ExprValue = Union[List[object], Dict[str, object], str, bool]
-# FIXME: Consolidate and centralize definitions for TopLevelExpr,
-# _ExprValue, _JSONValue, and _JSONObject; currently scattered across
-# several modules.
+
+class QAPIExpression(Dict[str, object]):
+ # pylint: disable=too-few-public-methods
+ def __init__(self,
+ data: Mapping[str, object],
+ info: QAPISourceInfo,
+ doc: Optional['QAPIDoc'] = None):
+ super().__init__(data)
+ self.info = info
+ self.doc: Optional['QAPIDoc'] = doc
class QAPIParseError(QAPISourceError):
@@ -100,7 +105,7 @@ class QAPISchemaParser:
self.line_pos = 0
# Parser output:
- self.exprs: List[Dict[str, object]] = []
+ self.exprs: List[QAPIExpression] = []
self.docs: List[QAPIDoc] = []
# Showtime!
@@ -147,8 +152,7 @@ class QAPISchemaParser:
"value of 'include' must be a string")
incl_fname = os.path.join(os.path.dirname(self._fname),
include)
- self.exprs.append({'expr': {'include': incl_fname},
- 'info': info})
+ self._add_expr(OrderedDict({'include': incl_fname}), info)
exprs_include = self._include(include, info, incl_fname,
self._included)
if exprs_include:
@@ -165,17 +169,18 @@ class QAPISchemaParser:
for name, value in pragma.items():
self._pragma(name, value, info)
else:
- expr_elem = {'expr': expr,
- 'info': info}
- if cur_doc:
- if not cur_doc.symbol:
- raise QAPISemError(
- cur_doc.info, "definition documentation required")
- expr_elem['doc'] = cur_doc
- self.exprs.append(expr_elem)
+ if cur_doc and not cur_doc.symbol:
+ raise QAPISemError(
+ cur_doc.info, "definition documentation required")
+ self._add_expr(expr, info, cur_doc)
cur_doc = None
self.reject_expr_doc(cur_doc)
+ def _add_expr(self, expr: Mapping[str, object],
+ info: QAPISourceInfo,
+ doc: Optional['QAPIDoc'] = None) -> None:
+ self.exprs.append(QAPIExpression(expr, info, doc))
+
@staticmethod
def reject_expr_doc(doc: Optional['QAPIDoc']) -> None:
if doc and doc.symbol:
@@ -784,7 +789,7 @@ class QAPIDoc:
% feature.name)
self.features[feature.name].connect(feature)
- def check_expr(self, expr: TopLevelExpr) -> None:
+ def check_expr(self, expr: QAPIExpression) -> None:
if self.has_section('Returns') and 'command' not in expr:
raise QAPISemError(self.info,
"'Returns:' is only valid for commands")