| 1 | module errors |
| 2 | |
| 3 | import v2.token |
| 4 | import term |
| 5 | |
| 6 | pub enum Kind { |
| 7 | warning |
| 8 | notice |
| 9 | error |
| 10 | } |
| 11 | |
| 12 | pub fn (e Kind) str() string { |
| 13 | return match e { |
| 14 | .warning { 'warning' } |
| 15 | .notice { 'notice' } |
| 16 | .error { 'error' } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | pub fn (e Kind) color(s string) string { |
| 21 | return match e { |
| 22 | .warning { term.yellow(s) } |
| 23 | .notice { term.blue(s) } |
| 24 | .error { term.red(s) } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | pub fn error(msg string, details string, kind Kind, pos token.Position) { |
| 29 | eprintln(pos.str() + ' -> ' + term.bold(kind.color(kind.str())) + ': ' + msg) |
| 30 | if details.len > 0 { |
| 31 | eprintln(details) |
| 32 | } |
| 33 | } |
| 34 | |