blob: 16a25d00bb62f31ab4c7f8eabb48f624b12b616b [file] [log] [blame]
Anthony Liguori5ab85582009-11-11 10:39:14 -06001/*
Markus Armbruster86cdf9e2018-08-23 18:40:20 +02002 * JSON Parser
Anthony Liguori5ab85582009-11-11 10:39:14 -06003 *
4 * Copyright IBM, Corp. 2009
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
11 *
12 */
13
Markus Armbruster86cdf9e2018-08-23 18:40:20 +020014#ifndef JSON_PARSER_INT_H
15#define JSON_PARSER_INT_H
16
17#include "qapi/qmp/json-parser.h"
Anthony Liguori5ab85582009-11-11 10:39:14 -060018
Anthony Liguori5ab85582009-11-11 10:39:14 -060019typedef enum json_token_type {
Markus Armbruster2ce4ee62018-08-31 09:58:40 +020020 JSON_ERROR = 0, /* must be zero, see json_lexer[] */
21 /* Gap for lexer states */
22 JSON_LCURLY = 100,
23 JSON_MIN = JSON_LCURLY,
Markus Armbrusterc5461662015-11-25 22:23:26 +010024 JSON_RCURLY,
25 JSON_LSQUARE,
26 JSON_RSQUARE,
27 JSON_COLON,
28 JSON_COMMA,
Anthony Liguori5ab85582009-11-11 10:39:14 -060029 JSON_INTEGER,
30 JSON_FLOAT,
31 JSON_KEYWORD,
32 JSON_STRING,
Markus Armbruster61030282018-08-23 18:40:04 +020033 JSON_INTERP,
Markus Armbrusterf9277912018-08-23 18:40:12 +020034 JSON_END_OF_INPUT,
Markus Armbrusterc0ee3af2018-08-31 09:58:38 +020035 JSON_MAX = JSON_END_OF_INPUT
Anthony Liguori5ab85582009-11-11 10:39:14 -060036} JSONTokenType;
37
Markus Armbruster86cdf9e2018-08-23 18:40:20 +020038typedef struct JSONToken JSONToken;
Anthony Liguori5ab85582009-11-11 10:39:14 -060039
Markus Armbruster86cdf9e2018-08-23 18:40:20 +020040/* json-lexer.c */
Markus Armbruster2cbd15a2018-08-23 18:40:05 +020041void json_lexer_init(JSONLexer *lexer, bool enable_interpolation);
Marc-André Lureau7c1e1d52018-08-23 18:39:58 +020042void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);
Marc-André Lureau7c1e1d52018-08-23 18:39:58 +020043void json_lexer_flush(JSONLexer *lexer);
Anthony Liguori5ab85582009-11-11 10:39:14 -060044void json_lexer_destroy(JSONLexer *lexer);
45
Markus Armbruster86cdf9e2018-08-23 18:40:20 +020046/* json-streamer.c */
47void json_message_process_token(JSONLexer *lexer, GString *input,
48 JSONTokenType type, int x, int y);
49
50/* json-parser.c */
51JSONToken *json_token(JSONTokenType type, int x, int y, GString *tokstr);
52QObject *json_parser_parse(GQueue *tokens, va_list *ap, Error **errp);
53
Anthony Liguori5ab85582009-11-11 10:39:14 -060054#endif