blob: 61a143f5bf210b75588a8052402deb474e4d36f0 [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
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +010017#include "qapi/qmp/qstring.h"
18#include "qapi/qmp/qlist.h"
Anthony Liguori5ab85582009-11-11 10:39:14 -060019
20typedef enum json_token_type {
Markus Armbrusterb8d3b1d2015-11-25 22:23:25 +010021 JSON_MIN = 100,
22 JSON_OPERATOR = JSON_MIN,
Anthony Liguori5ab85582009-11-11 10:39:14 -060023 JSON_INTEGER,
24 JSON_FLOAT,
25 JSON_KEYWORD,
26 JSON_STRING,
27 JSON_ESCAPE,
28 JSON_SKIP,
Michael Rothb011f612011-06-01 12:14:58 -050029 JSON_ERROR,
Anthony Liguori5ab85582009-11-11 10:39:14 -060030} JSONTokenType;
31
32typedef struct JSONLexer JSONLexer;
33
34typedef void (JSONLexerEmitter)(JSONLexer *, QString *, JSONTokenType, int x, int y);
35
36struct JSONLexer
37{
38 JSONLexerEmitter *emit;
39 int state;
40 QString *token;
41 int x, y;
42};
43
44void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter func);
45
46int json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);
47
48int json_lexer_flush(JSONLexer *lexer);
49
50void json_lexer_destroy(JSONLexer *lexer);
51
52#endif