From patchwork Fri Oct 19 02:42:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 192490 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 55E922C0080 for ; Fri, 19 Oct 2012 13:54:43 +1100 (EST) Received: from localhost ([::1]:56923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TP2Yj-00060i-IH for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2012 22:43:37 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TP2Y2-0004TX-Lf for qemu-devel@nongnu.org; Thu, 18 Oct 2012 22:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TP2Y1-0002wE-At for qemu-devel@nongnu.org; Thu, 18 Oct 2012 22:42:54 -0400 Received: from mail-oa0-f45.google.com ([209.85.219.45]:49553) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TP2Y1-0002dj-2U for qemu-devel@nongnu.org; Thu, 18 Oct 2012 22:42:53 -0400 Received: by mail-oa0-f45.google.com with SMTP id i18so3273oag.4 for ; Thu, 18 Oct 2012 19:42:52 -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=OgpSPOsXd0ka7htEeRWJ0p/MqjN9nxvKhRRiiuq978kYLrP0bLWweFfvwT3aVnAT7z ewiJcW3KCneSnkASgeBRTOLkG5ByO3auGO5sjyBn0zsvaxXAtQfLAwNGwXC/3jU4Qevb A8q3xbvuPLg6QirHd0CATXcsZ7iVeoozzB9HL1Hp5PxZwDu9o206ayyUujBy5+4R4XMB CMCZA5CONCydW13tZOXgH2noOMsHkQ1Qaa1VPMdiCJnUaJC2TYafIBMNaZIt64spuV2c 2HfRf3C+EH+IbkmRt1HBU/Vzi0ZaCt5CnSJLYT5bFvoBhCyGlsCJbtPo6QjMXZ8fa6rp mRJA== Received: by 10.60.6.33 with SMTP id x1mr21355904oex.78.1350614572645; Thu, 18 Oct 2012 19:42:52 -0700 (PDT) Received: from loki.austin.ibm.com ([32.97.110.59]) by mx.google.com with ESMTPS id m6sm475144obk.3.2012.10.18.19.42.51 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 18 Oct 2012 19:42:52 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2012 21:42:08 -0500 Message-Id: <1350614540-28583-15-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1350614540-28583-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1350614540-28583-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.219.45 Cc: kwolf@redhat.com, peter.maydell@linaro.org, aliguori@us.ibm.com, blauwirbel@gmail.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 14/26] 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)