use crate::heap::Address;
use crate::syntax::{Position, VarName};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
UnexpectedChar {
at: Position,
ch: char,
},
UnexpectedEnd {
expected: &'static str,
},
UnexpectedToken {
at: Position,
expected: &'static str,
found: String,
},
UnboundVariable {
name: VarName,
},
FuelExhausted {
limit: u64,
},
DanglingReference {
address: Address,
},
NotAReference {
found: String,
},
NotAFunction {
found: String,
},
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::UnexpectedChar { at, ch } => {
write!(f, "unexpected character {ch:?} at byte {}", at.value())
}
Self::UnexpectedEnd { expected } => {
write!(f, "unexpected end of input; expected {expected}")
}
Self::UnexpectedToken {
at,
expected,
found,
} => {
write!(
f,
"unexpected token {found:?} at byte {}; expected {expected}",
at.value()
)
}
Self::UnboundVariable { name } => {
write!(f, "unbound variable {:?}", name.as_str())
}
Self::FuelExhausted { limit } => {
write!(f, "evaluation exceeded step limit of {limit}")
}
Self::DanglingReference { address } => {
write!(f, "dangling reference to address {address}")
}
Self::NotAReference { found } => {
write!(f, "expected a reference, found {found}")
}
Self::NotAFunction { found } => {
write!(f, "expected a function, found {found}")
}
}
}
}
impl std::error::Error for Error {}