From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmg1i-0003OL-8r for qemu-devel@nongnu.org; Tue, 20 May 2014 05:08:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wmg1a-000802-6m for qemu-devel@nongnu.org; Tue, 20 May 2014 05:08:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmg1Z-0007zn-VD for qemu-devel@nongnu.org; Tue, 20 May 2014 05:07:54 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4K97rB1002153 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 May 2014 05:07:53 -0400 From: Fam Zheng Date: Tue, 20 May 2014 17:07:55 +0800 Message-Id: <1400576881-6954-2-git-send-email-famz@redhat.com> In-Reply-To: <1400576881-6954-1-git-send-email-famz@redhat.com> References: <1400576881-6954-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [RFC PATCH v2 1/7] qapi: Allow decimal values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi This allows giving decimal constants in the schema as expr. Signed-off-by: Fam Zheng --- 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