From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com,
eblake@redhat.com
Subject: [Qemu-devel] [PATCH v2 5/6] json: Eliminate lexer state IN_ERROR
Date: Fri, 31 Aug 2018 09:58:40 +0200 [thread overview]
Message-ID: <20180831075841.13363-6-armbru@redhat.com> (raw)
In-Reply-To: <20180831075841.13363-1-armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
qobject/json-lexer.c | 9 +++++----
qobject/json-parser-int.h | 8 ++++----
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 39c7ce7adc..2a5561c917 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -100,8 +100,7 @@
*/
enum json_lexer_state {
- IN_ERROR = 0, /* must really be 0, see json_lexer[] */
- IN_RECOVERY,
+ IN_RECOVERY = 1,
IN_DQ_STRING_ESCAPE,
IN_DQ_STRING,
IN_SQ_STRING_ESCAPE,
@@ -121,6 +120,8 @@ enum json_lexer_state {
IN_START_INTERP, /* must be IN_START + 1 */
};
+QEMU_BUILD_BUG_ON(JSON_ERROR != 0);
+QEMU_BUILD_BUG_ON(IN_RECOVERY != JSON_ERROR + 1);
QEMU_BUILD_BUG_ON((int)JSON_MIN <= (int)IN_START_INTERP);
QEMU_BUILD_BUG_ON(JSON_MAX >= 0x80);
QEMU_BUILD_BUG_ON(IN_START_INTERP != IN_START + 1);
@@ -176,7 +177,7 @@ static const uint8_t json_lexer[][256] = {
/* Zero */
[IN_ZERO] = {
TERMINAL(JSON_INTEGER),
- ['0' ... '9'] = IN_ERROR,
+ ['0' ... '9'] = JSON_ERROR,
['.'] = IN_MANTISSA,
},
@@ -328,7 +329,7 @@ static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
case IN_START:
new_state = lexer->start_state;
break;
- case IN_ERROR:
+ case JSON_ERROR:
json_message_process_token(lexer, lexer->token, JSON_ERROR,
lexer->x, lexer->y);
new_state = IN_RECOVERY;
diff --git a/qobject/json-parser-int.h b/qobject/json-parser-int.h
index abeec63af5..57cb8e79d3 100644
--- a/qobject/json-parser-int.h
+++ b/qobject/json-parser-int.h
@@ -16,10 +16,11 @@
#include "qapi/qmp/json-parser.h"
-
typedef enum json_token_type {
- JSON_MIN = 100,
- JSON_LCURLY = JSON_MIN,
+ JSON_ERROR = 0, /* must be zero, see json_lexer[] */
+ /* Gap for lexer states */
+ JSON_LCURLY = 100,
+ JSON_MIN = JSON_LCURLY,
JSON_RCURLY,
JSON_LSQUARE,
JSON_RSQUARE,
@@ -31,7 +32,6 @@ typedef enum json_token_type {
JSON_STRING,
JSON_INTERP,
JSON_SKIP,
- JSON_ERROR,
JSON_END_OF_INPUT,
JSON_MAX = JSON_END_OF_INPUT
} JSONTokenType;
--
2.17.1
next prev parent reply other threads:[~2018-08-31 7:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-31 7:58 [Qemu-devel] [PATCH v2 0/6] json: More fixes, error reporting improvements, cleanups Markus Armbruster
2018-08-31 7:58 ` [Qemu-devel] [PATCH v2 1/6] json: Fix lexer for lookahead character beyond '\x7F' Markus Armbruster
2018-08-31 7:58 ` [Qemu-devel] [PATCH v2 2/6] json: Clean up how lexer consumes "end of input" Markus Armbruster
2018-08-31 7:58 ` [Qemu-devel] [PATCH v2 3/6] json: Make lexer's "character consumed" logic less confusing Markus Armbruster
2018-08-31 7:58 ` [Qemu-devel] [PATCH v2 4/6] json: Nicer recovery from lexical errors Markus Armbruster
2018-08-31 7:58 ` Markus Armbruster [this message]
2018-08-31 7:58 ` [Qemu-devel] [PATCH v2 6/6] json: Eliminate lexer state IN_WHITESPACE, pseudo-token JSON_SKIP 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=20180831075841.13363-6-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=eblake@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).