diff options
-rw-r--r-- | scripts/qapi/parser.py | 14 | ||||
-rw-r--r-- | tests/qapi-schema/non-objects.err | 2 | ||||
-rw-r--r-- | tests/qapi-schema/quoted-structural-chars.err | 2 |
3 files changed, 10 insertions, 8 deletions
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 0bc852e..ffdd429 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -78,7 +78,11 @@ class QAPISchemaParser: self.docs.append(cur_doc) continue - expr = self.get_expr(False) + expr = self.get_expr() + if not isinstance(expr, dict): + raise QAPISemError( + info, "top-level expression must be an object") + if 'include' in expr: self.reject_expr_doc(cur_doc) if len(expr) != 1: @@ -251,7 +255,7 @@ class QAPISchemaParser: self.accept() if key in expr: raise QAPIParseError(self, "duplicate key '%s'" % key) - expr[key] = self.get_expr(True) + expr[key] = self.get_expr() if self.tok == '}': self.accept() return expr @@ -270,7 +274,7 @@ class QAPISchemaParser: raise QAPIParseError( self, "expected '{', '[', ']', string, or boolean") while True: - expr.append(self.get_expr(True)) + expr.append(self.get_expr()) if self.tok == ']': self.accept() return expr @@ -278,9 +282,7 @@ class QAPISchemaParser: raise QAPIParseError(self, "expected ',' or ']'") self.accept() - def get_expr(self, nested): - if self.tok != '{' and not nested: - raise QAPIParseError(self, "expected '{'") + def get_expr(self): if self.tok == '{': self.accept() expr = self.get_members() diff --git a/tests/qapi-schema/non-objects.err b/tests/qapi-schema/non-objects.err index 3a4ea36..23bdb69 100644 --- a/tests/qapi-schema/non-objects.err +++ b/tests/qapi-schema/non-objects.err @@ -1 +1 @@ -non-objects.json:1:1: expected '{' +non-objects.json:1: top-level expression must be an object diff --git a/tests/qapi-schema/quoted-structural-chars.err b/tests/qapi-schema/quoted-structural-chars.err index 07d1561..af6c1e1 100644 --- a/tests/qapi-schema/quoted-structural-chars.err +++ b/tests/qapi-schema/quoted-structural-chars.err @@ -1 +1 @@ -quoted-structural-chars.json:1:1: expected '{' +quoted-structural-chars.json:1: top-level expression must be an object |