qapi.py: Fix diagnosing non-objects at a schema's top-level

Report syntax error instead of crashing.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1374939721-7876-8-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Markus Armbruster 2013-07-27 17:41:59 +02:00 committed by Anthony Liguori
parent 6974ccd542
commit 5f3cd2b717
3 changed files with 8 additions and 6 deletions

View File

@ -64,7 +64,7 @@ def __init__(self, fp):
self.accept()
while self.tok != None:
self.exprs.append(self.get_expr())
self.exprs.append(self.get_expr(False))
def accept(self):
while True:
@ -117,7 +117,7 @@ def get_members(self):
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
@ -135,7 +135,7 @@ def get_values(self):
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
@ -143,7 +143,9 @@ def get_values(self):
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()

View File

@ -1 +1 @@
Crashed: <type 'exceptions.AttributeError'>
<stdin>:1:1: Expected "{"

View File

@ -1 +1 @@
Crashed: <type 'exceptions.AttributeError'>
<stdin>:1:1: Expected "{"