-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson.xh
More file actions
46 lines (36 loc) · 833 Bytes
/
Copy pathjson.xh
File metadata and controls
46 lines (36 loc) · 833 Bytes
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
#include <string.xh>
#include <vector.xh>
#include <stdlib.h>
#ifndef _JSON_XH
#define _JSON_XH
// TODO: belongs in a more general library
template <typename T>
datatype Result {
Ok(T value);
Err(string msg);
};
template <typename T>
_Bool isErr(Result<T> r) {
return match (r) (Ok(_) -> 0; Err(_) -> 1;);
}
typedef datatype Json Json;
typedef struct JsonItem JsonItem;
datatype Json {
JsonNull();
JsonBool(_Bool b);
JsonInteger(long i);
JsonNumber(double f);
JsonString(string s);
JsonArray(vector<Json> a);
JsonObject(vector<JsonItem> o);
};
struct JsonItem {
string key;
Json value;
};
size_t showJsonMaxLen(Json j);
size_t showJson(char buf[], Json j);
show datatype Json with showJsonMaxLen, showJson;
Result<Json> parseJson(string s, arena_t ar);
Json getJsonField(Json j, string key);
#endif