2022-08-04 16:43:51 +03:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2022-08-22 23:20:50 +03:00
|
|
|
pub enum ErrorKind {
|
2022-08-09 18:56:21 +03:00
|
|
|
DuplicateAttrsKey {
|
|
|
|
key: String,
|
|
|
|
},
|
|
|
|
|
2022-08-11 15:29:11 +03:00
|
|
|
AttributeNotFound {
|
|
|
|
name: String,
|
|
|
|
},
|
|
|
|
|
2022-08-08 02:16:02 +03:00
|
|
|
TypeError {
|
|
|
|
expected: &'static str,
|
|
|
|
actual: &'static str,
|
|
|
|
},
|
2022-08-11 11:37:04 +03:00
|
|
|
|
|
|
|
Incomparable {
|
|
|
|
lhs: &'static str,
|
|
|
|
rhs: &'static str,
|
|
|
|
},
|
2022-08-12 18:12:28 +03:00
|
|
|
|
|
|
|
// Resolving a user-supplied path literal failed in some way.
|
|
|
|
PathResolution(String),
|
2022-08-13 19:42:50 +03:00
|
|
|
|
|
|
|
// Dynamic keys are not allowed in let.
|
|
|
|
DynamicKeyInLet(rnix::SyntaxNode),
|
2022-08-13 20:17:25 +03:00
|
|
|
|
|
|
|
// Unknown variable in statically known scope.
|
2022-08-16 23:43:45 +03:00
|
|
|
UnknownStaticVariable(rnix::ast::Ident),
|
2022-08-15 01:13:17 +03:00
|
|
|
|
|
|
|
// Unknown variable in dynamic scope (with, rec, ...).
|
|
|
|
UnknownDynamicVariable(String),
|
2022-08-15 01:47:30 +03:00
|
|
|
|
|
|
|
ParseErrors(Vec<rnix::parser::ParseError>),
|
2022-08-16 15:53:35 +03:00
|
|
|
|
|
|
|
AssertionFailed,
|
2022-08-08 02:16:02 +03:00
|
|
|
}
|
2022-08-04 16:43:51 +03:00
|
|
|
|
2022-08-22 23:20:50 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
pub node: Option<rnix::SyntaxNode>,
|
|
|
|
pub kind: ErrorKind,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ErrorKind> for Error {
|
|
|
|
fn from(kind: ErrorKind) -> Self {
|
|
|
|
Error { node: None, kind }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-04 16:43:51 +03:00
|
|
|
impl Display for Error {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
2022-08-22 23:20:50 +03:00
|
|
|
writeln!(f, "{:?}", self.kind)
|
2022-08-04 16:43:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type EvalResult<T> = Result<T, Error>;
|