qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 3/6] json: Make lexer's "character consumed" logic less confusing
Date: Mon, 27 Aug 2018 12:04:58 -0500	[thread overview]
Message-ID: <c7f6a3aa-c4d3-494f-b8a7-b92cb6f2478d@redhat.com> (raw)
In-Reply-To: <20180827070021.11931-4-armbru@redhat.com>

On 08/27/2018 02:00 AM, Markus Armbruster wrote:
> The lexer uses macro TERMINAL_NEEDED_LOOKAHEAD() to decide whether a
> state transition consumes the input character.  It returns true when
> the state transition is defined with the TERMINAL() macro.  To detect
> that, it checks whether input '\0' would have resulted in the same
> state transition, and the new state is not IN_ERROR.
> 
> Why does that even work?  For all states, the new state on input '\0'
> is either IN_ERROR or defined with TERMINAL().  If the state
> transition equals the one we'd get for input '\0', it goes to IN_ERROR
> or to the argument of TERMINAL().  We never use TERMINAL(IN_ERROR),
> because it makes no sense.  Thus, if it doesn't go to IN_ERROR, it
> must be defined with TERMINAL().
> 
> Since this isn't quite confusing enough, we negate the result to get
> @char_consumed, and ignore it when @flush is true.
> 
> Instead of deriving the lookahead bit from the state transition, make
> it explicit.  This is easier to understand, and a bit more flexible,
> too.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>   qobject/json-lexer.c      | 27 ++++++++++++++++-----------
>   qobject/json-parser-int.h |  1 +
>   2 files changed, 17 insertions(+), 11 deletions(-)
> 

Good description of the convoluted logic. And yes, I find the new 
version more legible, even if more lines of code.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

  reply	other threads:[~2018-08-27 17:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-27  7:00 [Qemu-devel] [PATCH 0/6] json: More fixes, error reporting improvements, cleanups Markus Armbruster
2018-08-27  7:00 ` [Qemu-devel] [PATCH 1/6] json: Fix lexer for lookahead character beyond '\x7F' Markus Armbruster
2018-08-27 16:50   ` Eric Blake
2018-08-28  4:28     ` Markus Armbruster
2018-08-27  7:00 ` [Qemu-devel] [PATCH 2/6] json: Clean up how lexer consumes "end of input" Markus Armbruster
2018-08-27 16:58   ` Eric Blake
2018-08-28  4:28     ` Markus Armbruster
2018-08-27  7:00 ` [Qemu-devel] [PATCH 3/6] json: Make lexer's "character consumed" logic less confusing Markus Armbruster
2018-08-27 17:04   ` Eric Blake [this message]
2018-08-27  7:00 ` [Qemu-devel] [PATCH 4/6] json: Nicer recovery from lexical errors Markus Armbruster
2018-08-27 17:18   ` Eric Blake
2018-08-28  4:35     ` Markus Armbruster
2018-08-27  7:00 ` [Qemu-devel] [PATCH 5/6] json: Eliminate lexer state IN_ERROR Markus Armbruster
2018-08-27 17:20   ` Eric Blake
2018-08-27 17:29   ` Eric Blake
2018-08-28  4:40     ` Markus Armbruster
2018-08-28 15:01       ` Eric Blake
2018-08-28 15:04         ` Eric Blake
2018-08-31  7:08           ` Markus Armbruster
2018-08-31  7:06         ` Markus Armbruster
2018-08-27  7:00 ` [Qemu-devel] [PATCH 6/6] json: Eliminate lexer state IN_WHITESPACE, pseudo-token JSON_SKIP Markus Armbruster
2018-08-27 17:25   ` Eric Blake
2018-08-28  4:41     ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c7f6a3aa-c4d3-494f-b8a7-b92cb6f2478d@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).