Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 1 | /* |
| 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 Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 17 | |
| 18 | typedef enum json_token_type { |
Markus Armbruster | b8d3b1d | 2015-11-25 22:23:25 +0100 | [diff] [blame] | 19 | JSON_MIN = 100, |
Markus Armbruster | c546166 | 2015-11-25 22:23:26 +0100 | [diff] [blame] | 20 | JSON_LCURLY = JSON_MIN, |
| 21 | JSON_RCURLY, |
| 22 | JSON_LSQUARE, |
| 23 | JSON_RSQUARE, |
| 24 | JSON_COLON, |
| 25 | JSON_COMMA, |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 26 | JSON_INTEGER, |
| 27 | JSON_FLOAT, |
| 28 | JSON_KEYWORD, |
| 29 | JSON_STRING, |
Markus Armbruster | 6103028 | 2018-08-23 18:40:04 +0200 | [diff] [blame^] | 30 | JSON_INTERP, |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 31 | JSON_SKIP, |
Michael Roth | b011f61 | 2011-06-01 12:14:58 -0500 | [diff] [blame] | 32 | JSON_ERROR, |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 33 | } JSONTokenType; |
| 34 | |
Markus Armbruster | 037f244 | 2018-08-23 18:40:00 +0200 | [diff] [blame] | 35 | typedef struct JSONLexer { |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 36 | int state; |
Paolo Bonzini | d2ca7c0 | 2015-11-25 22:23:29 +0100 | [diff] [blame] | 37 | GString *token; |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 38 | int x, y; |
Markus Armbruster | 037f244 | 2018-08-23 18:40:00 +0200 | [diff] [blame] | 39 | } JSONLexer; |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 40 | |
Markus Armbruster | 037f244 | 2018-08-23 18:40:00 +0200 | [diff] [blame] | 41 | void json_lexer_init(JSONLexer *lexer); |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 42 | |
Marc-André Lureau | 7c1e1d5 | 2018-08-23 18:39:58 +0200 | [diff] [blame] | 43 | void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size); |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 44 | |
Marc-André Lureau | 7c1e1d5 | 2018-08-23 18:39:58 +0200 | [diff] [blame] | 45 | void json_lexer_flush(JSONLexer *lexer); |
Anthony Liguori | 5ab8558 | 2009-11-11 10:39:14 -0600 | [diff] [blame] | 46 | |
| 47 | void json_lexer_destroy(JSONLexer *lexer); |
| 48 | |
| 49 | #endif |