1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::fmt;
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use crate::ASTTy;
use crate::common::position::Position;
use crate::common::result::{format_err, WithSource};
use crate::generate::ast::node::Core;
pub type GenResult<T = Core> = Result<T, Box<UnimplementedErr>>;
const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Debug, Clone)]
pub struct UnimplementedErr {
pub position: Position,
pub msg: String,
pub source: Option<String>,
pub path: Option<PathBuf>,
}
impl UnimplementedErr {
pub fn new(ast: &ASTTy, msg: &str) -> UnimplementedErr {
let msg = format!("The {msg} construct has not yet been implemented as of v{VERSION}");
UnimplementedErr { position: ast.pos, msg, source: None, path: None }
}
}
impl WithSource for UnimplementedErr {
fn with_source(self, source: &Option<String>, path: &Option<PathBuf>) -> UnimplementedErr {
UnimplementedErr { source: source.clone(), path: path.clone(), ..self }
}
}
impl Display for UnimplementedErr {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
format_err(f, &self.msg, &self.path, Some(self.position), &self.source, &[])
}
}