use std::fmt;
pub const SPEC_DOMAIN_TAG: &str = "clm.spec.v1";
pub const SPEC_HASH_QUALIFIER: &str = crate::layer0::vocabulary::HASH_ALGORITHM_BLAKE3;
pub const MAX_SAFE_INTEGER: i64 = crate::layer0::limits::SPEC_MAX_SAFE_INTEGER;
pub const MIN_SAFE_INTEGER: i64 = -MAX_SAFE_INTEGER;
pub const MAX_NESTING_DEPTH: usize = crate::layer0::limits::SPEC_MAX_NESTING_DEPTH as usize;
pub const MAX_RECIPE_DEPTH: usize = crate::layer0::limits::SPEC_MAX_RECIPE_DEPTH as usize;
pub const REFUSED_FLOAT: &str = "float";
pub const REFUSED_DUPLICATE_KEY: &str = "duplicate_key";
pub const REFUSED_NON_ASCII_KEY: &str = "non_ascii_key";
pub const REFUSED_INTEGER_RANGE: &str = "integer_out_of_range";
pub const REFUSED_UNSUPPORTED_TYPE: &str = "unsupported_type";
pub const REFUSED_INVALID_STRING: &str = "invalid_string";
pub const REFUSED_MALFORMED: &str = "malformed";
pub const REFUSED_ACTION_OPERAND: &str = "action_operand";
pub const REFUSED_UNRESOLVED_INPUT: &str = "unresolved_input";
pub const REFUSED_UNKNOWN_COMPONENT: &str = "unknown_component";
pub const OPERAND_REFERENCE: &str = "reference";
pub const OPERAND_DEFERRED: &str = "deferred";
pub const OPERAND_ACTION: &str = "action";
pub const KIND_RECIPE: &str = "recipe";
pub const KIND_DEEP_KEY: &str = "deep_key";
pub const KIND_SHALLOW_KEY: &str = "shallow_key";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SpecProfileError {
pub reason: &'static str,
pub detail: String,
}
impl SpecProfileError {
pub(crate) fn new(reason: &'static str, detail: impl Into<String>) -> Self {
Self { reason, detail: detail.into() }
}
}
impl fmt::Display for SpecProfileError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}: {}", self.reason, self.detail)
}
}
impl std::error::Error for SpecProfileError {}
pub(crate) type Refusable<T> = Result<T, SpecProfileError>;
pub(crate) fn descend(depth: usize, limit: usize, what: &str) -> Refusable<usize> {
if depth >= limit {
return Err(SpecProfileError::new(REFUSED_MALFORMED, format!("{what} nests deeper than {limit} levels")));
}
Ok(depth + 1)
}
pub(crate) fn is_safe_integer(integer: i64) -> bool {
(MIN_SAFE_INTEGER..=MAX_SAFE_INTEGER).contains(&integer)
}