summaryrefslogtreecommitdiff
path: root/src/dged/json.h
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-05-22 00:00:29 +0200
committerAlbert Cervin <albert@acervin.com>2024-09-12 20:17:56 +0200
commit405da5f84b072ea97b69359454899f45d92d24b6 (patch)
tree20525b4bc44a5d8cbab4d62abe8413e174731db6 /src/dged/json.h
parent4ab7e453e26afc6e9f4938c65f89463fbba9e267 (diff)
downloaddged-405da5f84b072ea97b69359454899f45d92d24b6.tar.gz
dged-405da5f84b072ea97b69359454899f45d92d24b6.tar.xz
dged-405da5f84b072ea97b69359454899f45d92d24b6.zip
WIP LSP client
This contains the start of an LSP client. Nothing (except starting the LSP server) works at the moment and the feature is disabled by default.
Diffstat (limited to 'src/dged/json.h')
-rw-r--r--src/dged/json.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/dged/json.h b/src/dged/json.h
new file mode 100644
index 0000000..c0428b9
--- /dev/null
+++ b/src/dged/json.h
@@ -0,0 +1,54 @@
+#ifndef _JSON_H
+#define _JSON_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "s8.h"
+
+enum json_type {
+ Json_Array,
+ Json_Object,
+ Json_Null,
+ Json_Number,
+ Json_String,
+ Json_Bool,
+};
+
+struct json_value {
+ enum json_type type;
+ union {
+ struct s8 string;
+ struct json_object *object;
+ struct json_array *array;
+ double number;
+ bool boolean;
+ } value;
+};
+
+struct json_result {
+ bool ok;
+ union {
+ const char *error;
+ struct json_value document;
+ } result;
+};
+
+struct json_writer;
+
+struct json_result json_parse(uint8_t *buf, uint64_t size);
+void json_destroy(struct json_value *value);
+
+uint64_t json_len(struct json_object *obj);
+bool json_contains(struct json_object *obj, struct s8 key);
+struct json_value *json_get(struct json_object *obj, struct s8 key);
+
+uint64_t json_array_len(struct json_array *arr);
+void json_array_foreach(struct json_array *arr,
+ void (*cb)(uint64_t, struct json_value));
+struct json_value *json_array_get(struct json_array *arr, uint64_t idx);
+
+struct json_writer *json_writer_create();
+struct s8 json_writer_done(struct json_writer *writer);
+
+#endif