From patchwork Fri Aug 3 16:42:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 175018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 677AE2C007C for ; Sat, 4 Aug 2012 02:43:03 +1000 (EST) Received: from localhost ([::1]:35521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxKxp-0006hd-Gd for incoming@patchwork.ozlabs.org; Fri, 03 Aug 2012 12:43:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxKxV-0006BL-W5 for qemu-devel@nongnu.org; Fri, 03 Aug 2012 12:42:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SxKxK-0002S3-JZ for qemu-devel@nongnu.org; Fri, 03 Aug 2012 12:42:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48098) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxKxK-0002Rp-Aa for qemu-devel@nongnu.org; Fri, 03 Aug 2012 12:42:30 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q73GgTgn025738 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Aug 2012 12:42:29 -0400 Received: from localhost (ovpn-113-174.phx2.redhat.com [10.3.113.174]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q73GgSen009064; Fri, 3 Aug 2012 12:42:29 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Fri, 3 Aug 2012 13:42:55 -0300 Message-Id: <1344012178-21084-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1344012178-21084-1-git-send-email-lcapitulino@redhat.com> References: <1344012178-21084-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, Markus Armbruster Subject: [Qemu-devel] [PATCH 1/4] qapi: qapi.py: allow the "'" character to be escaped X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Support escaping the escape character, and make more robust (don't die for '', handle ' without matching '. Signed-off-by: Markus Armbruster Reviewed-by: Peter Maydell Signed-off-by: Luiz Capitulino --- scripts/qapi.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 8082af3..d3b8b4d 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -13,18 +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 = '' - while data[0] != "'": - string += data[0] + esc = False + while True: + 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):