53 lines
894 B
Rust
53 lines
894 B
Rust
use leaf_parser::{LineCol, ParseError};
|
|
use std::ops::Range;
|
|
|
|
use crate::SourceFile;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub enum Kind {
|
|
Unknown = 0x0000,
|
|
|
|
Parsing = 0x0100,
|
|
|
|
SymbolNotFound = 0x0200,
|
|
UninitializedSymbol = 0x0201,
|
|
NotAType = 0x0202,
|
|
|
|
FunctionCompilationFailed = 0x0301,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Location {
|
|
None,
|
|
Range {
|
|
file: SourceFile,
|
|
range: Range<usize>,
|
|
},
|
|
Position {
|
|
file: SourceFile,
|
|
position: LineCol,
|
|
},
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct CompilationError {
|
|
pub kind: Kind,
|
|
pub message: String,
|
|
pub location: Location,
|
|
pub cause: Option<Box<CompilationError>>,
|
|
}
|
|
|
|
impl CompilationError {
|
|
pub fn parsing(file: SourceFile, err: ParseError<LineCol>) -> Self {
|
|
Self {
|
|
kind: Kind::Parsing,
|
|
message: err.to_string(),
|
|
location: Location::Position {
|
|
file,
|
|
position: err.location,
|
|
},
|
|
cause: None,
|
|
}
|
|
}
|
|
}
|