blob: 8bce6ef67646b257fbba54f3340db7a0188cd15d [file] [log] [blame]
Anthony Liguori5ab85582009-11-11 10:39:14 -06001/*
2 * JSON lexer
3 *
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
14#ifndef QEMU_JSON_LEXER_H
15#define QEMU_JSON_LEXER_H
16
Anthony Liguori5ab85582009-11-11 10:39:14 -060017
18typedef enum json_token_type {
Markus Armbrusterb8d3b1d2015-11-25 22:23:25 +010019 JSON_MIN = 100,
Markus Armbrusterc5461662015-11-25 22:23:26 +010020 JSON_LCURLY = JSON_MIN,
21 JSON_RCURLY,
22 JSON_LSQUARE,
23 JSON_RSQUARE,
24 JSON_COLON,
25 JSON_COMMA,
Anthony Liguori5ab85582009-11-11 10:39:14 -060026 JSON_INTEGER,
27 JSON_FLOAT,
28 JSON_KEYWORD,
29 JSON_STRING,
Markus Armbruster61030282018-08-23 18:40:04 +020030 JSON_INTERP,
Anthony Liguori5ab85582009-11-11 10:39:14 -060031 JSON_SKIP,
Michael Rothb011f612011-06-01 12:14:58 -050032 JSON_ERROR,
Anthony Liguori5ab85582009-11-11 10:39:14 -060033} JSONTokenType;
34
Markus Armbruster037f2442018-08-23 18:40:00 +020035typedef struct JSONLexer {
Anthony Liguori5ab85582009-11-11 10:39:14 -060036 int state;
Paolo Bonzinid2ca7c02015-11-25 22:23:29 +010037 GString *token;
Anthony Liguori5ab85582009-11-11 10:39:14 -060038 int x, y;
Markus Armbruster037f2442018-08-23 18:40:00 +020039} JSONLexer;
Anthony Liguori5ab85582009-11-11 10:39:14 -060040
Markus Armbruster037f2442018-08-23 18:40:00 +020041void json_lexer_init(JSONLexer *lexer);
Anthony Liguori5ab85582009-11-11 10:39:14 -060042
Marc-André Lureau7c1e1d52018-08-23 18:39:58 +020043void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);
Anthony Liguori5ab85582009-11-11 10:39:14 -060044
Marc-André Lureau7c1e1d52018-08-23 18:39:58 +020045void json_lexer_flush(JSONLexer *lexer);
Anthony Liguori5ab85582009-11-11 10:39:14 -060046
47void json_lexer_destroy(JSONLexer *lexer);
48
49#endif