kojote/parse/types.ha

33 lines
921 B
Hare
Raw Normal View History

2024-12-04 16:29:11 +00:00
use io;
use fmt;
2024-12-04 17:56:08 +00:00
export type invalid = !(uint, uint);
export type unterminated = !(const str, uint, uint);
export type error = !(invalid | unterminated | io::error);
2024-12-04 16:29:11 +00:00
2024-12-04 17:56:08 +00:00
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 | bool);
2024-12-04 16:29:11 +00:00
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);
2024-12-04 17:56:08 +00:00
case let err: unterminated =>
return fmt::bsprintf(buf,
"{}:{}: Unterminated {} found", err.1, err.2, err.0);
2024-12-04 16:29:11 +00:00
case let err: io::error =>
return io::strerror(err);
};
};