summaryrefslogtreecommitdiff
path: root/src/json.h
diff options
context:
space:
mode:
authorDylan <boss@tehbox.org>2026-06-06 19:36:41 +1200
committerDylan <boss@tehbox.org>2026-06-06 19:36:41 +1200
commit1d379a5cf34475f66f2ab9359f77dac162c0a40e (patch)
tree395d54815331fbcad053001bf5cb28fafb69e9d4 /src/json.h
parent46c896bcd78d31130321562b0659e28230261b8e (diff)
downloadtehjson-1d379a5cf34475f66f2ab9359f77dac162c0a40e.tar.gz
tehjson-1d379a5cf34475f66f2ab9359f77dac162c0a40e.zip
feat: JSON reading
- Implemented a tokenizer for json - Implemented a method which will read json from a string using the tokenizer
Diffstat (limited to 'src/json.h')
-rw-r--r--src/json.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/json.h b/src/json.h
index d1d7938..efde542 100644
--- a/src/json.h
+++ b/src/json.h
@@ -1,7 +1,12 @@
+#pragma once
+
+#include "tokenizer.h"
+
#include <cstddef>
#include <map>
#include <memory>
#include <string>
+#include <vector>
namespace TehJSON
{
@@ -12,14 +17,19 @@ namespace TehJSON
JSON(const JSON& other) = default;
~JSON();
+ // Writing methods
+ std::string getSerialized();
+ std::string _getSerialized(int currIndent);
+
+ // Reading methods
+ void readFromString(std::string s);
+
// Leaf methods
template <typename T>
T& get();
template <typename T>
void set(T value);
std::string leafType();
- std::string getSerialized();
- std::string _getSerialized(int currIndent);
template <typename T>
static std::string serializeData(std::shared_ptr<void> data);
@@ -30,6 +40,14 @@ namespace TehJSON
private:
bool isLeaf = false;
+ // Reading data fields
+ std::vector<Token> tokens;
+ int tokenPos = 0;
+ Token consume();
+ Token consume(TokenType type);
+ TokenType nextTokenType();
+ int readFromTokens(std::vector<Token> tokens, int pos);
+
// Leaf data fields
std::shared_ptr<void> data;
std::string (*dataSerializer)(std::shared_ptr<void>);