1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#ifndef LCOLONQ_JSON_H
#define LCOLONQ_JSON_H
#include <lcq/prelude.h>
typedef enum {
JSON_TOKEN__ERROR=-1,
JSON_TOKEN__START=0,
JSON_TOKEN_NUMBER_INT,
JSON_TOKEN_NUMBER_FLOAT,
JSON_TOKEN_STRING,
JSON_TOKEN_LSQUARE,
JSON_TOKEN_RSQUARE,
JSON_TOKEN_LCURLY,
JSON_TOKEN_RCURLY,
JSON_TOKEN_COMMA,
JSON_TOKEN_COLON,
JSON_TOKEN__END,
} json_token;
typedef struct {
u8 *buf;
i64 size;
i64 start, end;
} json_lexer;
char *json_token_name(json_token t);
void json_lexer_new(json_lexer *l, u8 *buf, i64 size);
json_token json_lex(json_lexer *l);
typedef enum {
JSON_VALUE_TYPE__ERROR=-1,
JSON_VALUE_TYPE_NUMBER=1,
JSON_VALUE_TYPE_STRING,
JSON_VALUE_TYPE_ARRAY,
JSON_VALUE_TYPE_OBJECT,
} json_value_type;
typedef struct {
i64 idx;
} json_value;
typedef struct {
i64 idx;
} json_array_iter;
typedef struct {
json_lexer lex;
json_token next;
i64 curstart, curend;
} json_parser;
void json_parser_new(json_parser *p, u8 *buf, i64 size);
json_value json_parse(json_parser *p);
json_value_type json_value_get_type(json_parser *p, json_value v);
char *json_value_as_string(json_parser *p, json_value v);
i64 json_value_as_number(json_parser *p, json_value v);
json_array_iter json_value_as_array(json_parser *p, json_value v);
json_value json_array_iter_get(json_parser *p, json_array_iter i);
bool json_array_iter_next(json_parser *p, json_array_iter *i);
#endif
|