32 lines
914 B
Hare
32 lines
914 B
Hare
use io;
|
|
use fmt;
|
|
|
|
export type invalid = !(uint, uint);
|
|
export type unterminated = !(const str, uint, uint);
|
|
export type error = !(invalid | unterminated | io::error);
|
|
|
|
export type quotstart = void;
|
|
export type quotend = void;
|
|
export type mapstart = void;
|
|
export type mapend = void;
|
|
|
|
export type comment = struct { v: str };
|
|
export type word = struct { v: str };
|
|
export type symbol = struct { v: str, kw: bool };
|
|
|
|
export type token = (quotstart | quotend | mapstart | mapend |
|
|
word | symbol | comment | str | rune);
|
|
|
|
export fn strerror(err: error) const str = {
|
|
static let buf: [64]u8 = [0...];
|
|
match (err) {
|
|
case let err: invalid =>
|
|
return fmt::bsprintf(buf,
|
|
"{}:{}: Invalid token found", err.0, err.1);
|
|
case let err: unterminated =>
|
|
return fmt::bsprintf(buf,
|
|
"{}:{}: Unterminated {} found", err.1, err.2, err.0);
|
|
case let err: io::error =>
|
|
return io::strerror(err);
|
|
};
|
|
};
|