From patchwork Wed Oct 31 22:36:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 196059 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 8FEEE2C024D for ; Thu, 1 Nov 2012 10:40:43 +1100 (EST) Received: from localhost ([::1]:48859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTguu-0002ep-IM for incoming@patchwork.ozlabs.org; Wed, 31 Oct 2012 18:37:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTgu7-0001Dy-61 for qemu-devel@nongnu.org; Wed, 31 Oct 2012 18:36:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTgu6-0005qU-1s for qemu-devel@nongnu.org; Wed, 31 Oct 2012 18:36:55 -0400 Received: from mail-ia0-f173.google.com ([209.85.210.173]:37027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTgu5-0005ku-TU for qemu-devel@nongnu.org; Wed, 31 Oct 2012 18:36:53 -0400 Received: by mail-ia0-f173.google.com with SMTP id m10so1511545iam.4 for ; Wed, 31 Oct 2012 15:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=kB+xSoKwLhxA6tf1JLua2i+lICOqrrMKKa408dtEBdo=; b=uSuln/Z25vnxKEguC4CLEMKmCT44IY4VwKjJ/xA1R6iQWKAeTUPBODgUyDOCbXVMyN rJs2+Jt9zEhtYs0f05dBgYrkR0y01pv8JDX1GQ41NYyhxPGxirzc6MLO3W7TxVwZZPg9 EntqZ2AuXCn4f/GB/NNk/8OLdVp7wjcyXzxIrcR7/a3/1q7D0CCTL1apJ3PVUGWyq3kn fmMeDIYbyIu/S5TCGn1cC+ILVbPy0Z9Zeo19BmlGiOoGOdnnuBYX0ghwSBAUe5r+RUnW g2a5jlueX+DOpe6baunNZaxRwP5gOr5+WcAC2MPlMY3x8RJepaJDkGXY+MHkYWOcbJPS fZRA== Received: by 10.50.219.229 with SMTP id pr5mr3206424igc.59.1351723013659; Wed, 31 Oct 2012 15:36:53 -0700 (PDT) Received: from loki.morrigu.org (cpe-72-179-62-111.austin.res.rr.com. [72.179.62.111]) by mx.google.com with ESMTPS id hg2sm11556858igc.3.2012.10.31.15.36.52 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Oct 2012 15:36:53 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2012 17:36:00 -0500 Message-Id: <1351722972-17801-17-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1351722972-17801-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1351722972-17801-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.173 Cc: kwolf@redhat.com, peter.maydell@linaro.org, aliguori@us.ibm.com, blauwirbel@gmail.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 16/28] qapi: qapi.py, make json parser more robust 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 Currently the QAPI JSON parser expects a very particular style of code indentation, the major one being that terminating curly/square brackets are not on placed on a seperate line. This is incompatible with most pretty-print formats, so make it a little more robust by supporting these cases. Also add support for parsing numerical fields. Currently they are ignored. QIDL will make use of both of these changes with the schemas it generates. Reviewed-by: Paolo Bonzini Signed-off-by: Michael Roth --- scripts/qapi.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 555d823..333f375 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -37,6 +37,12 @@ def tokenize(data): else: string += ch yield string + elif ch.isdigit(): + number = ch + while data[0].isdigit(): + number += data[0] + data = data[1:] + yield number def parse(tokens): if tokens[0] == '{': @@ -81,7 +87,7 @@ def parse_schema(fp): if line.startswith('#') or line == '\n': continue - if line.startswith(' '): + if line[0] in ['}', ']', ' ', '\t']: expr += line elif expr: expr_eval = evaluate(expr)