blob: afee7828cd9a32b07119e720a70438363513bb69 [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,
30 JSON_ESCAPE,
31 JSON_SKIP,
Michael Rothb011f612011-06-01 12:14:58 -050032 JSON_ERROR,
Anthony Liguori5ab85582009-11-11 10:39:14 -060033} JSONTokenType;
34
35typedef struct JSONLexer JSONLexer;
36
Paolo Bonzinid2ca7c02015-11-25 22:23:29 +010037typedef void (JSONLexerEmitter)(JSONLexer *, GString *,
38 JSONTokenType, int x, int y);
Anthony Liguori5ab85582009-11-11 10:39:14 -060039
40struct JSONLexer
41{
42 JSONLexerEmitter *emit;
43 int state;
Paolo Bonzinid2ca7c02015-11-25 22:23:29 +010044 GString *token;
Anthony Liguori5ab85582009-11-11 10:39:14 -060045 int x, y;
46};
47
48void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter func);
49
50int json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);
51
52int json_lexer_flush(JSONLexer *lexer);
53
54void json_lexer_destroy(JSONLexer *lexer);
55
56#endif