| 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. The line number at which parsing |
| 9 |
// failed is stored in the error. |
| 10 |
export type syntaxerr = !size; |
| 11 |
|
| 12 |
// Any error that may occur during parsing. |
| 13 |
export type error = !(io::error | utf8::invalid | syntaxerr); |
| 14 |
|
| 15 |
// Returns a user-friendly representation of [[error]]. The result may be |
| 16 |
// statically allocated. |
| 17 |
export fn strerror(err: error) const str = { |
| 18 |
match (err) { |
| 19 |
case let err: io::error => |
| 20 |
return io::strerror(err); |
| 21 |
case utf8::invalid => |
| 22 |
return "File is invalid UTF-8"; |
| 23 |
case let s: syntaxerr => |
| 24 |
static let buf: [20 + len("line : Invalid syntax")]u8 = [0...]; |
| 25 |
return fmt::bsprintf(buf, "line {}: Invalid syntax", s: size)!; |
| 26 |
}; |
| 27 |
}; |