use std::{fmt, sync::Arc};
use crate::{ast::AstFunctionDecl, builtin::Builtin, common::Identifier, evaluate::Environment};
#[derive(Clone, Eq, PartialEq)]
pub(crate) enum SassFunction {
Builtin(Builtin, Identifier),
UserDefined(UserDefinedFunction),
Plain {
name: Identifier,
},
}
#[derive(Debug, Clone)]
pub(crate) struct UserDefinedFunction {
pub function: Arc<AstFunctionDecl>,
pub name: Identifier,
pub env: Environment,
}
impl PartialEq for UserDefinedFunction {
fn eq(&self, other: &Self) -> bool {
self.function == other.function && self.name == other.name
}
}
impl Eq for UserDefinedFunction {}
impl SassFunction {
pub fn name(&self) -> Identifier {
match self {
Self::Builtin(_, name)
| Self::UserDefined(UserDefinedFunction { name, .. })
| Self::Plain { name } => *name,
}
}
fn kind(&self) -> &'static str {
match &self {
Self::Plain { .. } => "Plain",
Self::Builtin(..) => "Builtin",
Self::UserDefined { .. } => "UserDefined",
}
}
}
impl fmt::Debug for SassFunction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SassFunction")
.field("name", &self.name())
.field("kind", &self.kind())
.finish()
}
}