hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

types.ha (1371B)


      1 // License: MPL-2.0
      2 // (c) 2022 Drew DeVault <sir@cmpwn.com>
      3 use fmt;
      4 use io;
      5 
      6 // An invalid JSON token was encountered at this location (line, column).
      7 export type invalid = !(uint, uint);
      8 
      9 // The maximum nesting limit was reached.
     10 export type limitreached = !void;
     11 
     12 // A tagged union of all possible errors returned from this module.
     13 export type error = !(invalid | limitreached | io::error);
     14 
     15 // The JSON null value.
     16 export type _null = void;
     17 
     18 // The '[' token, signaling the start of a JSON array.
     19 export type arraystart = void;
     20 
     21 // The ']' token, signaling the end of a JSON array.
     22 export type arrayend = void;
     23 
     24 // The '{' token, signaling the start of a JSON object.
     25 export type objstart = void;
     26 
     27 // The '}' token, signaling the end of a JSON object.
     28 export type objend = void;
     29 
     30 // The ':' token.
     31 export type colon = void;
     32 
     33 // The ',' token.
     34 export type comma = void;
     35 
     36 // All tokens which can be returned from the JSON tokenizer.
     37 export type token = (arraystart | arrayend | objstart |
     38 	objend | colon | comma | str | f64 | bool | _null);
     39 
     40 // Converts an [[error]] into a human-friendly string.
     41 export fn strerror(err: error) const str = {
     42 	static let buf: [53]u8 = [0...];
     43 	match (err) {
     44 	case let err: invalid =>
     45 		return fmt::bsprintf(buf,
     46 			"{}:{}: Invalid JSON token encountered", err.0, err.1);
     47 	case let err: io::error =>
     48 		return io::strerror(err);
     49 	};
     50 };