summaryrefslogtreecommitdiff
path: root/encoding/json/types.ha
diff options
context:
space:
mode:
authorLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:11:21 +0200
committerLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:51:35 +0200
commitae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch)
tree5f462459ae4b47d22114eed717d1382d08cf4dfe /encoding/json/types.ha
Initial commit (import old repo)HEADmain
Diffstat (limited to 'encoding/json/types.ha')
-rw-r--r--encoding/json/types.ha50
1 files changed, 50 insertions, 0 deletions
diff --git a/encoding/json/types.ha b/encoding/json/types.ha
new file mode 100644
index 0000000..1e1b433
--- /dev/null
+++ b/encoding/json/types.ha
@@ -0,0 +1,50 @@
+// License: MPL-2.0
+// (c) 2022 Drew DeVault <sir@cmpwn.com>
+use fmt;
+use io;
+
+// An invalid JSON token was encountered at this location (line, column).
+export type invalid = !(uint, uint);
+
+// The maximum nesting limit was reached.
+export type limitreached = !void;
+
+// A tagged union of all possible errors returned from this module.
+export type error = !(invalid | limitreached | io::error);
+
+// The JSON null value.
+export type _null = void;
+
+// The '[' token, signaling the start of a JSON array.
+export type arraystart = void;
+
+// The ']' token, signaling the end of a JSON array.
+export type arrayend = void;
+
+// The '{' token, signaling the start of a JSON object.
+export type objstart = void;
+
+// The '}' token, signaling the end of a JSON object.
+export type objend = void;
+
+// The ':' token.
+export type colon = void;
+
+// The ',' token.
+export type comma = void;
+
+// All tokens which can be returned from the JSON tokenizer.
+export type token = (arraystart | arrayend | objstart |
+ objend | colon | comma | str | f64 | bool | _null);
+
+// Converts an [[error]] into a human-friendly string.
+export fn strerror(err: error) const str = {
+ static let buf: [53]u8 = [0...];
+ match (err) {
+ case let err: invalid =>
+ return fmt::bsprintf(buf,
+ "{}:{}: Invalid JSON token encountered", err.0, err.1);
+ case let err: io::error =>
+ return io::strerror(err);
+ };
+};