json: Eliminate lexer state IN_ERROR
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180831075841.13363-6-armbru@redhat.com>
This commit is contained in:
parent
0f07a5d5f1
commit
2ce4ee64c4
|
@ -100,8 +100,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum json_lexer_state {
|
enum json_lexer_state {
|
||||||
IN_ERROR = 0, /* must really be 0, see json_lexer[] */
|
IN_RECOVERY = 1,
|
||||||
IN_RECOVERY,
|
|
||||||
IN_DQ_STRING_ESCAPE,
|
IN_DQ_STRING_ESCAPE,
|
||||||
IN_DQ_STRING,
|
IN_DQ_STRING,
|
||||||
IN_SQ_STRING_ESCAPE,
|
IN_SQ_STRING_ESCAPE,
|
||||||
|
@ -121,6 +120,8 @@ enum json_lexer_state {
|
||||||
IN_START_INTERP, /* must be IN_START + 1 */
|
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((int)JSON_MIN <= (int)IN_START_INTERP);
|
||||||
QEMU_BUILD_BUG_ON(JSON_MAX >= 0x80);
|
QEMU_BUILD_BUG_ON(JSON_MAX >= 0x80);
|
||||||
QEMU_BUILD_BUG_ON(IN_START_INTERP != IN_START + 1);
|
QEMU_BUILD_BUG_ON(IN_START_INTERP != IN_START + 1);
|
||||||
|
@ -176,7 +177,7 @@ static const uint8_t json_lexer[][256] = {
|
||||||
/* Zero */
|
/* Zero */
|
||||||
[IN_ZERO] = {
|
[IN_ZERO] = {
|
||||||
TERMINAL(JSON_INTEGER),
|
TERMINAL(JSON_INTEGER),
|
||||||
['0' ... '9'] = IN_ERROR,
|
['0' ... '9'] = JSON_ERROR,
|
||||||
['.'] = IN_MANTISSA,
|
['.'] = IN_MANTISSA,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -328,7 +329,7 @@ static void json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
|
||||||
case IN_START:
|
case IN_START:
|
||||||
new_state = lexer->start_state;
|
new_state = lexer->start_state;
|
||||||
break;
|
break;
|
||||||
case IN_ERROR:
|
case JSON_ERROR:
|
||||||
json_message_process_token(lexer, lexer->token, JSON_ERROR,
|
json_message_process_token(lexer, lexer->token, JSON_ERROR,
|
||||||
lexer->x, lexer->y);
|
lexer->x, lexer->y);
|
||||||
new_state = IN_RECOVERY;
|
new_state = IN_RECOVERY;
|
||||||
|
|
|
@ -16,10 +16,11 @@
|
||||||
|
|
||||||
#include "qapi/qmp/json-parser.h"
|
#include "qapi/qmp/json-parser.h"
|
||||||
|
|
||||||
|
|
||||||
typedef enum json_token_type {
|
typedef enum json_token_type {
|
||||||
JSON_MIN = 100,
|
JSON_ERROR = 0, /* must be zero, see json_lexer[] */
|
||||||
JSON_LCURLY = JSON_MIN,
|
/* Gap for lexer states */
|
||||||
|
JSON_LCURLY = 100,
|
||||||
|
JSON_MIN = JSON_LCURLY,
|
||||||
JSON_RCURLY,
|
JSON_RCURLY,
|
||||||
JSON_LSQUARE,
|
JSON_LSQUARE,
|
||||||
JSON_RSQUARE,
|
JSON_RSQUARE,
|
||||||
|
@ -31,7 +32,6 @@ typedef enum json_token_type {
|
||||||
JSON_STRING,
|
JSON_STRING,
|
||||||
JSON_INTERP,
|
JSON_INTERP,
|
||||||
JSON_SKIP,
|
JSON_SKIP,
|
||||||
JSON_ERROR,
|
|
||||||
JSON_END_OF_INPUT,
|
JSON_END_OF_INPUT,
|
||||||
JSON_MAX = JSON_END_OF_INPUT
|
JSON_MAX = JSON_END_OF_INPUT
|
||||||
} JSONTokenType;
|
} JSONTokenType;
|
||||||
|
|
Loading…
Reference in New Issue