json handling: first draft
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 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/json/json.c b/json/json.c
new file mode 100644
index 0000000..cdb595a
--- /dev/null
+++ b/json/json.c
@@ -0,0 +1,37 @@
+/* kc3
+ * Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#include <libkc3/kc3.h>
+#include "json.h"
+#include "buf.h"
+#include "buf_parse.h"
+#include "tag.h"
+
+static bool parse_json(const s_buf *buf, s_tag *dest) {
+ assert(buf);
+ assert(dest);
+ if (buf_parse_tag_number(buf, dest) == 0)
+ return false;
+ return true;
+}
+
+s_tag *json_parse(const s_buf *buf, s_tag *dest) {
+ assert(buf);
+ assert(dest);
+ s_buf_save save;
+ buf_save_init(buf, &save);
+ if (!parse_json(buf, dest)) {
+ buf_restore_rpos(buf, &save);
+ return NULL;
+ }
+ return dest;
+}
\ No newline at end of file
diff --git a/json/json.h b/json/json.h
new file mode 100644
index 0000000..6e6a106
--- /dev/null
+++ b/json/json.h
@@ -0,0 +1,12 @@
+/* kc3
+ * Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
diff --git a/lib/kc3/0.1/json/parser.kc3 b/lib/kc3/0.1/json/parser.kc3
new file mode 100644
index 0000000..c7331f6
--- /dev/null
+++ b/lib/kc3/0.1/json/parser.kc3
@@ -0,0 +1,7 @@
+defmodule JSON.Parser do
+
+ dlopen(__DIR__ + "../json.so")
+
+ def parse = cfn Tag "json_parse" (Buf, Result)
+
+end
diff --git a/test/json/basics.kc3 b/test/json/basics.kc3
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/json/basics.kc3