kojote/parse/types.ha

32 lines
925 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 | bool);
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 at {}:{}", err.0, err.1);
case let err: unterminated =>
return fmt::bsprintf(buf,
"Unterminated {} found at {}:{}", err.0, err.1, err.2);
case let err: io::error =>
return io::strerror(err);
};
};