hare

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

types.ha (687B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use encoding::utf8;
      5 use fmt;
      6 use io;
      7 
      8 // A syntax error occurred during parsing.
      9 export type syntaxerr = !size;
     10 
     11 // Any error that may occur during parsing.
     12 export type error = !(io::error | utf8::invalid | syntaxerr);
     13 
     14 // Returns a user-friendly representation of [[error]]. The result may be
     15 // statically allocated.
     16 export fn strerror(err: error) const str = match (err) {
     17 case let err: io::error =>
     18 	return io::strerror(err);
     19 case utf8::invalid =>
     20 	return "File is invalid UTF-8";
     21 case let s: syntaxerr =>
     22 	static let buf: [1024]u8 = [0...];
     23 	yield fmt::bsprintf(buf, "{}: Invalid syntax", s: size);
     24 };