1use std::path::PathBuf;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum CompileErrorKind {
7 LexError, ParseError, SemanticError, IoError, }
12
13#[derive(Debug, Clone)]
14pub struct CompileError {
15 pub kind: CompileErrorKind,
16 pub location: SourceLocation,
17 pub message: String,
18 pub suggestion: Option<String>,
19}
20
21#[derive(Debug, Clone)]
22pub struct SourceLocation {
23 pub line: usize,
24 pub column: usize,
25 pub file: Option<PathBuf>,
26}
27
28impl std::fmt::Display for CompileError {
29 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
30 write!(
31 f,
32 "{:?} at {}:{}: {}",
33 self.kind, self.location.line, self.location.column, self.message
34 )
35 }
36}
37
38impl std::error::Error for CompileError {}