[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 7/9] qapi.py: Fix diagnosing non-objects at a schema
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 7/9] qapi.py: Fix diagnosing non-objects at a schema's top-level |
Date: |
Fri, 26 Jul 2013 14:39:45 +0200 |
Report syntax error instead of crashing.
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/qapi.py | 10 ++++++----
tests/qapi-schema/non-objects.err | 2 +-
tests/qapi-schema/quoted-structural-chars.err | 2 +-
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index a7feccb..5677daa 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -49,7 +49,7 @@ class QAPISchema:
self.accept()
while self.tok != None:
- self.exprs.append(self.get_expr())
+ self.exprs.append(self.get_expr(False))
def accept(self):
while True:
@@ -102,7 +102,7 @@ class QAPISchema:
if self.tok != ':':
raise QAPISchemaError(self, 'Expected ":"')
self.accept()
- expr[key] = self.get_expr()
+ expr[key] = self.get_expr(True)
if self.tok == '}':
self.accept()
return expr
@@ -120,7 +120,7 @@ class QAPISchema:
if not self.tok in [ '{', '[', "'" ]:
raise QAPISchemaError(self, 'Expected "{", "[", "]" or string')
while True:
- expr.append(self.get_expr())
+ expr.append(self.get_expr(True))
if self.tok == ']':
self.accept()
return expr
@@ -128,7 +128,9 @@ class QAPISchema:
raise QAPISchemaError(self, 'Expected "," or "]"')
self.accept()
- def get_expr(self):
+ def get_expr(self, nested):
+ if self.tok != '{' and not nested:
+ raise QAPISchemaError(self, 'Expected "{"')
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 48c849d..a6c2dc2 100644
--- a/tests/qapi-schema/non-objects.err
+++ b/tests/qapi-schema/non-objects.err
@@ -1 +1 @@
-Crashed: <type 'exceptions.AttributeError'>
+<stdin>:1:1: Expected "{"
diff --git a/tests/qapi-schema/quoted-structural-chars.err
b/tests/qapi-schema/quoted-structural-chars.err
index 48c849d..a6c2dc2 100644
--- a/tests/qapi-schema/quoted-structural-chars.err
+++ b/tests/qapi-schema/quoted-structural-chars.err
@@ -1 +1 @@
-Crashed: <type 'exceptions.AttributeError'>
+<stdin>:1:1: Expected "{"
--
1.7.11.7
- Re: [Qemu-devel] [PATCH 4/9] qapi.py: Decent syntax error reporting, (continued)
[Qemu-devel] [PATCH 5/9] qapi.py: Reject invalid characters in schema file, Markus Armbruster, 2013/07/26
[Qemu-devel] [PATCH 8/9] qapi.py: Rename expr_eval to expr in parse_schema(), Markus Armbruster, 2013/07/26
[Qemu-devel] [PATCH 9/9] qapi.py: Permit comments starting anywhere on the line, Markus Armbruster, 2013/07/26
[Qemu-devel] [PATCH 7/9] qapi.py: Fix diagnosing non-objects at a schema's top-level,
Markus Armbruster <=
[Qemu-devel] [PATCH 6/9] qapi.py: Fix schema parser to check syntax systematically, Markus Armbruster, 2013/07/26
[Qemu-devel] [PATCH 1/9] tests: QAPI schema parser tests, Markus Armbruster, 2013/07/26