-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.h
68 lines (55 loc) · 1.27 KB
/
json.h
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
64
65
66
67
68
#ifndef JSON_H
#define JSON_H 1
enum tokentype {
openbrace,
closebrace,
opensqbrace,
closesqbrace,
string,
number,
jsonnull,
jsontrue,
jsonfalse,
colon,
comma
};
enum jsontype {
jsontype_string,
jsontype_array,
jsontype_object,
jsontype_number,
jsontype_boolean,
jsontype_null
};
struct objitem {
char type; // can be object, string, array ,number, boolean
char* key;
void* value;
};
struct arrayitem {
char type; // can be object, string, array , number, boolean
void* value;
};
struct Token {
enum tokentype type;
void* value;
};
struct node {
void* ptr;
struct node* next;
};
struct object {
};
struct node* lex(char* jsonstr, size_t siz4e);
void addendnode(struct node** head, void* value);
struct Token* maketoken(enum tokentype type, void* value);
void* parse(struct node* tokens);
struct objitem* handlejsonobject(struct node* tokens, size_t len);
struct arrayitem* handlejsonarray(struct node* tokens, size_t len);
void jabort(char* message);
size_t getjsonobjectlen(struct node* tokens);
size_t getjsonarraylen(struct node* tokens);
void printarray(struct arrayitem* array);
void printobject(struct objitem* object);
#define cast2token(x) ((struct Token*)(x))
#endif