Received: from eggs.gnu.org ([2001:4830:134:3::10]:34884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1s3m-0007sk-AF for qemu-devel@nongnu.org; Thu, 26 Nov 2015 03:37:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1s3h-0001et-Ag for qemu-devel@nongnu.org; Thu, 26 Nov 2015 03:37:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1s3h-0001eo-5e for qemu-devel@nongnu.org; Thu, 26 Nov 2015 03:37:41 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id F2006C0D2226 for ; Thu, 26 Nov 2015 08:37:39 +0000 (UTC) From: Markus Armbruster References: <1448486613-17634-1-git-send-email-armbru@redhat.com> <1448486613-17634-10-git-send-email-armbru@redhat.com> <565634AA.1040703@redhat.com> Date: Thu, 26 Nov 2015 09:37:37 +0100 In-Reply-To: <565634AA.1040703@redhat.com> (Eric Blake's message of "Wed, 25 Nov 2015 15:22:34 -0700") Message-ID: <8737vtma0e.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3 for-2.5 09/12] qjson: Convert to parser to recursive descent List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com Eric Blake writes: > On 11/25/2015 02:23 PM, Markus Armbruster wrote: >> We backtrack in parse_value(), even though JSON is LL(1) and thus can >> be parsed by straightforward recursive descent. Do exactly that. >> >> Based on an almost-correct patch from Paolo Bonzini. >> >> Signed-off-by: Markus Armbruster >> --- >> qobject/json-parser.c | 165 ++++++++++++++------------------------------------ >> 1 file changed, 47 insertions(+), 118 deletions(-) >> > >> static QObject *parse_value(JSONParserContext *ctxt, va_list *ap) >> { >> - QObject *obj; >> + QObject *token; >> >> - obj = parse_object(ctxt, ap); >> - if (obj == NULL) { >> - obj = parse_array(ctxt, ap); >> - } >> - if (obj == NULL) { >> - obj = parse_escape(ctxt, ap); >> - } >> - if (obj == NULL) { >> - obj = parse_keyword(ctxt); >> - } >> - if (obj == NULL) { >> - obj = parse_literal(ctxt); >> + token = parser_context_peek_token(ctxt); >> + if (token == NULL) { >> + parse_error(ctxt, NULL, "premature EOI"); > > Should we spell that out as 'end of input'? > > But that's cosmetic, and doesn't affect correctness of the conversion. Doesn't matter, because we generally throw away these error messages, then make up a useless one *boggle*. Once that's fixed, the parse_error() could use some love. > Reviewed-by: Eric Blake Thanks!