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 6/6] json: Eliminate lexer state IN_WHITESPACE, pseudo-token JSON_SKIP
Date: Mon, 27 Aug 2018 12:25:02 -0500 [thread overview]
Message-ID: <9f11e72b-42c5-da48-3f70-7370d680d59d@redhat.com> (raw)
In-Reply-To: <20180827070021.11931-7-armbru@redhat.com>
On 08/27/2018 02:00 AM, Markus Armbruster wrote:
> The lexer ignores whitespace like this:
>
> on whitespace on non-ws spontaneously
> IN_START --> IN_WHITESPACE --> JSON_SKIP --> IN_START
> ^ |
> \__/ on whitespace
>
> This accumulates a whitespace token in state IN_WHITESPACE, only to
> throw it away on the transition via JSON_SKIP to the start state.
> Wasteful. Go from IN_START to IN_START on whitspace directly,
s/whitspace/whitespace/
> dropping the whitespace character.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> qobject/json-lexer.c | 22 +++++-----------------
> qobject/json-parser-int.h | 1 -
> 2 files changed, 5 insertions(+), 18 deletions(-)
>
> @@ -263,10 +253,10 @@ static const uint8_t json_lexer[][256] = {
> [','] = JSON_COMMA,
> [':'] = JSON_COLON,
> ['a' ... 'z'] = IN_KEYWORD,
> - [' '] = IN_WHITESPACE,
> - ['\t'] = IN_WHITESPACE,
> - ['\r'] = IN_WHITESPACE,
> - ['\n'] = IN_WHITESPACE,
> + [' '] = IN_START,
> + ['\t'] = IN_START,
> + ['\r'] = IN_START,
> + ['\n'] = IN_START,
> },
> [IN_START_INTERP]['%'] = IN_INTERP,
Don't you need to set [IN_START_INTERP][' '] to IN_START_INTERP, rather
than IN_START? Otherwise, the presence of skipped whitespace would
change whether interpolation happens. (At least, that's what you had in
an earlier version of this patch).
> };
> @@ -323,10 +313,8 @@ static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
> json_message_process_token(lexer, lexer->token, new_state,
> lexer->x, lexer->y);
> /* fall through */
> - case JSON_SKIP:
> - g_string_truncate(lexer->token, 0);
> - /* fall through */
> case IN_START:
> + g_string_truncate(lexer->token, 0);
> new_state = lexer->start_state;
Oh, I see. We are magically reverting to the correct start state if the
requested transition reports IN_START, rather than blindly using IN_START.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-08-27 17:25 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
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 [this message]
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=9f11e72b-42c5-da48-3f70-7370d680d59d@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.