From ae44478b30d890fe0fb04022f44d474dcdcc3f9d Mon Sep 17 00:00:00 2001 From: Lassi Pulkkinen Date: Thu, 31 Oct 2024 03:11:21 +0200 Subject: Initial commit (import old repo) --- encoding/json/types.ha | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 encoding/json/types.ha (limited to 'encoding/json/types.ha') 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 +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); + }; +}; -- cgit v1.2.3