blob: cb456d53e5594ad1280b1e991539cce0427034e0 [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 Bonzinid2ca7c02015-11-25 22:23:29 +010017#include "glib-compat.h"
Anthony Liguori5ab85582009-11-11 10:39:14 -060018
19typedef enum json_token_type {
Markus Armbrusterb8d3b1d2015-11-25 22:23:25 +010020 JSON_MIN = 100,
Markus Armbrusterc5461662015-11-25 22:23:26 +010021 JSON_LCURLY = JSON_MIN,
22 JSON_RCURLY,
23 JSON_LSQUARE,
24 JSON_RSQUARE,
25 JSON_COLON,
26 JSON_COMMA,
Anthony Liguori5ab85582009-11-11 10:39:14 -060027 JSON_INTEGER,
28 JSON_FLOAT,
29 JSON_KEYWORD,
30 JSON_STRING,
31 JSON_ESCAPE,
32 JSON_SKIP,
Michael Rothb011f612011-06-01 12:14:58 -050033 JSON_ERROR,
Anthony Liguori5ab85582009-11-11 10:39:14 -060034} JSONTokenType;
35
36typedef struct JSONLexer JSONLexer;
37
Paolo Bonzinid2ca7c02015-11-25 22:23:29 +010038typedef void (JSONLexerEmitter)(JSONLexer *, GString *,
39 JSONTokenType, int x, int y);
Anthony Liguori5ab85582009-11-11 10:39:14 -060040
41struct JSONLexer
42{
43 JSONLexerEmitter *emit;
44 int state;
Paolo Bonzinid2ca7c02015-11-25 22:23:29 +010045 GString *token;
Anthony Liguori5ab85582009-11-11 10:39:14 -060046 int x, y;
47};
48
49void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter func);
50
51int json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size);
52
53int json_lexer_flush(JSONLexer *lexer);
54
55void json_lexer_destroy(JSONLexer *lexer);
56
57#endif