1#[derive(Debug, Clone)]
2pub enum LingError {
3 Lex(String),
4 Parse(String),
5 Type(String),
6 Borrow(String),
7 Codegen(String),
8 Mir(String),
9 Io(String),
10}
11
12impl std::fmt::Display for LingError {
13 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14 match self {
15 Self::Lex(s) => write!(f, "Lexical error: {s}"),
16 Self::Parse(s) => write!(f, "Parse error: {s}"),
17 Self::Type(s) => write!(f, "Type error: {s}"),
18 Self::Borrow(s) => write!(f, "Borrow error: {s}"),
19 Self::Codegen(s) => write!(f, "Codegen error: {s}"),
20 Self::Mir(s) => write!(f, "MIR error: {s}"),
21 Self::Io(s) => write!(f, "I/O error: {s}"),
22 }
23 }
24}
25
26impl std::error::Error for LingError {}
27
28impl From<String> for LingError {
29 fn from(s: String) -> Self {
30 LingError::Mir(s)
31 }
32}
33
34impl From<std::io::Error> for LingError {
35 fn from(e: std::io::Error) -> Self {
36 LingError::Io(e.to_string())
37 }
38}