All of lore.kernel.org
 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 2/6] json: Clean up how lexer consumes "end of input"
Date: Mon, 27 Aug 2018 11:58:28 -0500	[thread overview]
Message-ID: <ef8a1994-4e57-ee0c-6dc3-793f94e15321@redhat.com> (raw)
In-Reply-To: <20180827070021.11931-3-armbru@redhat.com>

On 08/27/2018 02:00 AM, Markus Armbruster wrote:
> When the lexer isn't in its start state at the end of input, it's
> working on a token.  To flush it out, it needs to transit to its start
> state on "end of input" lookahead.
> 
> There are two ways to the start state, depending on the current state:
> 
> * If the lexer is in a TERMINAL(JSON_FOO) state, it can emit a
>    JSON_FOO token.
> 
> * Else, it can go to IN_ERROR state, and emit a JSON_ERROR token.
> 
> There are complications, however:
> 
> * The transition to IN_ERROR state consumes the input character and
>    adds it to the JSON_ERROR token.  The latter is inappropriate for
>    the "end of input" character, so we suppress that.  See also recent
>    commit "json: Fix lexer to include the bad character in JSON_ERROR
>    token".

Now commit a2ec6be7

> 
> * The transition to a TERMINAL(JSON_FOO) state doesn't consume the
>    input character.  In that case, the lexer normally loops until it is
>    consumed.  We have to suppress that for the "end of input" input
>    character.  If we didn't, the lexer would consume it by entering
>    IN_ERROR state, emitting a bogus JSON_ERROR token.  We fixed that in
>    commit bd3924a33a6.
> 
> However, simply breaking the loop this way assumes that the lexer
> needs exactly one state transition to reach its start state.  That
> assumption is correct now, but it's unclean, and I'll soon break it.
> Clean up: instead of breaking the loop after one iteration, break it
> after it reached the start state.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>   qobject/json-lexer.c | 17 +++++++++--------
>   1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
> index 4867839f66..ec3aec726f 100644
> --- a/qobject/json-lexer.c
> +++ b/qobject/json-lexer.c
> @@ -261,7 +261,8 @@ void json_lexer_init(JSONLexer *lexer, bool enable_interpolation)
>   
>   static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
>   {
> -    int char_consumed, new_state;
> +    int new_state;
> +    bool char_consumed = false;

Yay for the switch to bool.

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 16:58 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 [this message]
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
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=ef8a1994-4e57-ee0c-6dc3-793f94e15321@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.