From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Ep4-0006sE-OM for qemu-devel@nongnu.org; Thu, 23 Jan 2014 02:35:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6Eoz-0000Xq-Ae for qemu-devel@nongnu.org; Thu, 23 Jan 2014 02:35:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32057) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Eoz-0000X6-17 for qemu-devel@nongnu.org; Thu, 23 Jan 2014 02:35:29 -0500 From: Amos Kong Date: Thu, 23 Jan 2014 15:30:16 +0800 Message-Id: <1390462216-23273-1-git-send-email-akong@redhat.com> Subject: [Qemu-devel] [PATCH] qapi: store raw expressions to QAPISchema List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, mdroth@linux.vnet.ibm.com, aliguori@amazon.com, lcapitulino@redhat.com After cleaning up the comments of qapi-schema.json file, we get an range of raw expressions, they are also converted to ordered dictionaries. This patch just addes a member to QAPISchema to store the raw expressions. Actually this patch was split from QMP introspection patchset, it's no longer needed in that patchset. I would like to post this patch singly, we can apply it if it's useful. Signed-off-by: Amos Kong --- scripts/qapi.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 750e9fb..7b92689 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -61,10 +61,13 @@ class QAPISchema: self.src += '\n' self.cursor = 0 self.exprs = [] + self.raw_exprs = [] self.accept() while self.tok != None: - self.exprs.append(self.get_expr(False)) + self.cur_entry= '' + self.exprs.append(self.get_expr(False, True)) + self.raw_exprs.append(self.cur_entry) def accept(self): while True: @@ -103,9 +106,11 @@ class QAPISchema: elif not self.tok.isspace(): raise QAPISchemaError(self, 'Stray "%s"' % self.tok) - def get_members(self): + def get_members(self, start=None): expr = OrderedDict() if self.tok == '}': + if start != None: + self.cur_entry = self.src[start:self.cursor] self.accept() return expr if self.tok != "'": @@ -118,6 +123,8 @@ class QAPISchema: self.accept() expr[key] = self.get_expr(True) if self.tok == '}': + if start != None: + self.cur_entry = self.src[start:self.cursor] self.accept() return expr if self.tok != ',': @@ -142,12 +149,15 @@ class QAPISchema: raise QAPISchemaError(self, 'Expected "," or "]"') self.accept() - def get_expr(self, nested): + def get_expr(self, nested, first=False): if self.tok != '{' and not nested: raise QAPISchemaError(self, 'Expected "{"') if self.tok == '{': + start = None + if first: + start = self.cursor - 1 self.accept() - expr = self.get_members() + expr = self.get_members(start) elif self.tok == '[': self.accept() expr = self.get_values() -- 1.8.4.2