started working on a json library
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Jun 2021 19:54:22 +0000 (14:54 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 14 Jun 2021 19:54:22 +0000 (14:54 -0500)
modules/json/decoder.onyx [new file with mode: 0644]
modules/json/encoder.onyx [new file with mode: 0644]
modules/json/example.onyx [new file with mode: 0644]
modules/json/module.onyx [new file with mode: 0644]
modules/json/types.onyx [new file with mode: 0644]

diff --git a/modules/json/decoder.onyx b/modules/json/decoder.onyx
new file mode 100644 (file)
index 0000000..8d6443e
--- /dev/null
@@ -0,0 +1,11 @@
+package json
+use package core
+
+decode_string :: (data: str, allocator := context.allocator) -> Value {
+    stream := io.string_stream_make(data);
+    return decode(^stream, allocator);
+}
+
+decode :: (stream: ^io.Stream, allocator := context.allocator) -> Value {
+
+}
\ No newline at end of file
diff --git a/modules/json/encoder.onyx b/modules/json/encoder.onyx
new file mode 100644 (file)
index 0000000..09d5984
--- /dev/null
@@ -0,0 +1 @@
+package json
\ No newline at end of file
diff --git a/modules/json/example.onyx b/modules/json/example.onyx
new file mode 100644 (file)
index 0000000..04468ec
--- /dev/null
@@ -0,0 +1,17 @@
+
+#load "core/std"
+#load "modules/json/module"
+
+use package core
+json :: package json
+
+json_string := "{ \"test\": \"Hello, World!\", \"array\": [1,2,3,4,5], }";
+
+main :: (args: [] cstr) {
+    decoded_json := json.decode_string(json_string);
+    defer json.free(decoded_json);
+
+    test_str := decoded_json |> json.get("test")
+                             |> json.to_str();
+    println(test_str);
+}
\ No newline at end of file
diff --git a/modules/json/module.onyx b/modules/json/module.onyx
new file mode 100644 (file)
index 0000000..6d8d8ce
--- /dev/null
@@ -0,0 +1,7 @@
+
+
+
+package json
+
+#load "./encoder"
+#load "./decoder"
\ No newline at end of file
diff --git a/modules/json/types.onyx b/modules/json/types.onyx
new file mode 100644 (file)
index 0000000..cec32ef
--- /dev/null
@@ -0,0 +1,25 @@
+package json
+
+use package core.map { Map }
+
+Value :: struct {
+    Type :: enum {
+        Null;
+        Bool;
+        Integer;
+        Float;
+        String;
+        Array;
+        Object;
+    }
+
+    type  : Type;
+    value : struct #union {
+        bool_   : bool;
+        int_    : i64;
+        float_  : f64;
+        str_    : str;
+        array_  : [..] Value;
+        object_ : Map(str, Value);
+    }
+}
\ No newline at end of file