json-lexer.h revision 0fdfff3cce93e16179a454fd471cd1d9126204e0
1ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/*
2ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao * JSON lexer
3ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao *
4ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao * Copyright IBM, Corp. 2009
5ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao *
6ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao * Authors:
7ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao *  Anthony Liguori   <aliguori@us.ibm.com>
8ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao *
9ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao * See the COPYING.LIB file in the top-level directory.
11ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao *
12ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao */
13ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
14ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#ifndef QEMU_JSON_LEXER_H
15#define QEMU_JSON_LEXER_H
16
17#include "qapi/qmp/qstring.h"
18#include "qapi/qmp/qlist.h"
19
20typedef enum json_token_type {
21    JSON_OPERATOR = 100,
22    JSON_INTEGER,
23    JSON_FLOAT,
24    JSON_KEYWORD,
25    JSON_STRING,
26    JSON_ESCAPE,
27    JSON_SKIP,
28} JSONTokenType;
29
30typedef struct JSONLexer JSONLexer;
31
32typedef void (JSONLexerEmitter)(JSONLexer *, QString *, JSONTokenType, int x, int y);
33
34struct JSONLexer
35{
36    JSONLexerEmitter *emit;
37    int state;
38    QString *token;
39    int x, y;
40};
41
42void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter func);
43
44int json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);
45
46int json_lexer_flush(JSONLexer *lexer);
47
48void json_lexer_destroy(JSONLexer *lexer);
49
50#endif
51