This allows giving decimal constants in the schema as expr. Signed-off-by: Fam Zheng <f...@redhat.com> --- scripts/qapi.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py index 0265b40..4c945ad 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -157,6 +157,21 @@ class QAPISchema: return else: string += ch + elif self.tok in "-0123456789": + val = self.tok + while self.src[self.cursor] in "0123456789": + val += self.src[self.cursor] + self.cursor += 1 + try: + if val.startswith("0") and len(val) > 1: + raise Exception("Leading zero for non-zero integer") + self.val = int(val) + if self.val > 0x7fffffffffffffffL or self.val < -0x7fffffffffffffffL - 1: + raise Exception("Value too big") + return + except Exception, e: + raise QAPISchemaError(self, 'Invalid number "%s": %s' % (val, e)) + elif self.tok == '\n': if self.cursor == len(self.src): self.tok = None @@ -196,8 +211,8 @@ class QAPISchema: if self.tok == ']': self.accept() return expr - if not self.tok in [ '{', '[', "'" ]: - raise QAPISchemaError(self, 'Expected "{", "[", "]" or string') + if not self.tok in "{['-0123456789": + raise QAPISchemaError(self, 'Expected "{", "[", "]", string or number') while True: expr.append(self.get_expr(True)) if self.tok == ']': @@ -219,6 +234,9 @@ class QAPISchema: elif self.tok == "'": expr = self.val self.accept() + elif self.tok in "-0123456789": + expr = self.val + self.accept() else: raise QAPISchemaError(self, 'Expected "{", "[" or string') return expr -- 1.9.2