From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpLFA-0003fV-69 for qemu-devel@nongnu.org; Wed, 19 Jun 2013 12:28:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpLF8-0003ip-Tz for qemu-devel@nongnu.org; Wed, 19 Jun 2013 12:28:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpLF8-0003ie-Hq for qemu-devel@nongnu.org; Wed, 19 Jun 2013 12:28:22 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5JGSL0e025619 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Jun 2013 12:28:22 -0400 From: Kevin Wolf Date: Wed, 19 Jun 2013 18:28:05 +0200 Message-Id: <1371659287-14331-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1371659287-14331-1-git-send-email-kwolf@redhat.com> References: <1371659287-14331-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] qapi.py: Move common code to evaluate() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com, lcapitulino@redhat.com Don't duplicate more code than is really necessary. Signed-off-by: Kevin Wolf --- 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 -- 1.8.1.4