Received: from eggs.gnu.org ([208.118.235.92]:36209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SuSZV-00055H-K6 for qemu-devel@nongnu.org; Thu, 26 Jul 2012 14:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SuSZS-0005YM-8c for qemu-devel@nongnu.org; Thu, 26 Jul 2012 14:14:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SuSZR-0005YI-VU for qemu-devel@nongnu.org; Thu, 26 Jul 2012 14:13:58 -0400 From: Markus Armbruster References: <1343235256-26310-1-git-send-email-lcapitulino@redhat.com> <1343235256-26310-8-git-send-email-lcapitulino@redhat.com> <20120725161813.538012f0@doriath.home> <878ve6epif.fsf@blackfin.pond.sub.org> <20120726104749.5be67b6a@doriath.home> <87394ev6x9.fsf@blackfin.pond.sub.org> Date: Thu, 26 Jul 2012 19:09:13 +0200 In-Reply-To: <87394ev6x9.fsf@blackfin.pond.sub.org> (Markus Armbruster's message of "Thu, 26 Jul 2012 18:11:30 +0200") Message-ID: <87boj2o3eu.fsf_-_@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] fixup! qapi: qapi.py: allow the "'" character be escaped List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: Peter Maydell , aliguori@us.ibm.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com Support escaping the escape character, and make more robust (don't die for '', handle ' without matching '. Signed-off-by: Markus Armbruster --- Luiz made me do this. Fixes up his 07/11. Generates identical qmp-commands.h qapi-types.h qapi-visit.h qapi-errors.h tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h qapi-generated/qga-qapi-types.h qapi-generated/qga-qapi-visit.h qapi-generated/qga-qmp-commands.h scripts/qapi.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 9aa518f..169ea78 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -13,20 +13,29 @@ from ordereddict import OrderedDict def tokenize(data): while len(data): - if data[0] in ['{', '}', ':', ',', '[', ']']: - yield data[0] - data = data[1:] - elif data[0] in ' \n': - data = data[1:] - elif data[0] == "'": - data = data[1:] + ch = data[0] + data = data[1:] + if ch in ['{', '}', ':', ',', '[', ']']: + yield ch + elif ch in ' \n': + None + elif ch == "'": string = '' + esc = False while True: - if data[0] == "'" and string[len(string)-1] != "\\": - break - string += data[0] + if (data == ''): + raise Exception("Mismatched quotes") + ch = data[0] data = data[1:] - data = data[1:] + if esc: + string += ch + esc = False + elif ch == "\\": + esc = True + elif ch == "'": + break + else: + string += ch yield string def parse(tokens): -- 1.7.10.4