use crate::ast::CodeLocation;
#[cfg(feature = "codec")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(
feature = "codec",
derive(Serialize, Deserialize),
serde(tag = "type", content = "content")
)]
pub enum StateErrorKind {
Common,
ConstantAlreadyExist,
ConstantNotFound,
WrongLetType,
WrongExpressionType,
TypeAlreadyExist,
FunctionAlreadyExist,
ValueNotFound,
ValueNotStruct,
ValueNotStructField,
ValueIsNotMutable,
FunctionNotFound,
FunctionParameterTypeWrong,
ReturnNotFound,
ReturnAlreadyCalled,
IfElseDuplicated,
TypeNotFound,
WrongReturnType,
ConditionExpressionWrongType,
ConditionIsEmpty,
ConditionExpressionNotSupported,
ForbiddenCodeAfterReturnDeprecated,
ForbiddenCodeAfterContinueDeprecated,
ForbiddenCodeAfterBreakDeprecated,
FunctionArgumentNameDuplicated,
}
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "codec", derive(Serialize, Deserialize))]
pub struct StateErrorLocation(pub CodeLocation);
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "codec", derive(Serialize, Deserialize))]
pub struct StateErrorResult {
pub kind: StateErrorKind,
pub value: String,
pub location: StateErrorLocation,
}
impl StateErrorResult {
#[must_use]
pub const fn new(kind: StateErrorKind, value: String, location: CodeLocation) -> Self {
Self {
kind,
value,
location: StateErrorLocation(location),
}
}
}
impl StateErrorResult {
#[must_use]
pub fn trace_state(&self) -> String {
format!(
"[{:?}] for value {:?} at: {:?}:{:?}",
self.kind,
self.value,
self.location.0.line(),
self.location.0.offset()
)
}
}