From patchwork Fri Jun 21 15:46:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 253256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 11EE52C038C for ; Sat, 22 Jun 2013 01:52:56 +1000 (EST) Received: from localhost ([::1]:47444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uq3dt-0005lN-T3 for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2013 11:52:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uq3dN-0005jJ-FB for qemu-devel@nongnu.org; Fri, 21 Jun 2013 11:52:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uq3dM-0005nZ-4K for qemu-devel@nongnu.org; Fri, 21 Jun 2013 11:52:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55457) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uq3dL-0005nR-Rt for qemu-devel@nongnu.org; Fri, 21 Jun 2013 11:52:20 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5LFqJIV030495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Jun 2013 11:52:19 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5LFqEpE012522; Fri, 21 Jun 2013 11:52:17 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2013 17:46:27 +0200 Message-Id: <1371829589-18045-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1371829589-18045-1-git-send-email-kwolf@redhat.com> References: <1371829589-18045-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH v2 1/3] qapi.py: Move common code to evaluate() 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 Don't duplicate more code than is really necessary. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- scripts/qapi.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 02ad668..3a64769 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -76,12 +76,18 @@ def parse(tokens): return tokens[0], tokens[1:] def evaluate(string): - return parse(map(lambda x: x, tokenize(string)))[0] + expr_eval = parse(map(lambda x: x, tokenize(string)))[0] + + if expr_eval.has_key('enum'): + add_enum(expr_eval['enum']) + elif expr_eval.has_key('union'): + add_enum('%sKind' % expr_eval['union']) + + return expr_eval def parse_schema(fp): exprs = [] expr = '' - expr_eval = None for line in fp: if line.startswith('#') or line == '\n': @@ -90,23 +96,13 @@ def parse_schema(fp): if line.startswith(' '): expr += line elif expr: - expr_eval = evaluate(expr) - if expr_eval.has_key('enum'): - add_enum(expr_eval['enum']) - elif expr_eval.has_key('union'): - add_enum('%sKind' % expr_eval['union']) - exprs.append(expr_eval) + exprs.append(evaluate(expr)) expr = line else: expr += line if expr: - expr_eval = evaluate(expr) - if expr_eval.has_key('enum'): - add_enum(expr_eval['enum']) - elif expr_eval.has_key('union'): - add_enum('%sKind' % expr_eval['union']) - exprs.append(expr_eval) + exprs.append(evaluate(expr)) return exprs