2020-03-10 21:19:23 -04:00
|
|
|
use once_cell::sync::Lazy;
|
2020-03-03 19:51:02 -05:00
|
|
|
use std::collections::HashMap;
|
2020-04-03 23:47:56 -04:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
2020-01-25 20:58:30 -05:00
|
|
|
|
2020-01-25 23:33:45 -05:00
|
|
|
use crate::args::CallArgs;
|
2020-02-16 10:14:17 -05:00
|
|
|
use crate::error::SassResult;
|
2020-03-17 20:13:53 -04:00
|
|
|
use crate::scope::Scope;
|
2020-04-04 18:17:04 -04:00
|
|
|
use crate::selector::Selector;
|
2020-01-25 20:58:30 -05:00
|
|
|
use crate::value::Value;
|
|
|
|
|
2020-02-03 07:11:35 -05:00
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
2020-02-02 22:33:04 -05:00
|
|
|
|
2020-01-25 23:33:45 -05:00
|
|
|
mod color;
|
2020-02-02 18:05:36 -05:00
|
|
|
mod list;
|
|
|
|
mod map;
|
|
|
|
mod math;
|
|
|
|
mod meta;
|
|
|
|
mod selector;
|
|
|
|
mod string;
|
2020-01-25 23:33:45 -05:00
|
|
|
|
2020-04-30 15:00:57 -04:00
|
|
|
pub(crate) type GlobalFunctionMap = HashMap<&'static str, Builtin>;
|
|
|
|
|
2020-04-03 23:47:56 -04:00
|
|
|
static FUNCTION_COUNT: AtomicUsize = AtomicUsize::new(0);
|
|
|
|
|
|
|
|
// TODO: impl Fn
|
|
|
|
#[derive(Clone)]
|
2020-04-04 18:17:04 -04:00
|
|
|
pub(crate) struct Builtin(
|
|
|
|
pub fn(CallArgs, &Scope, &Selector) -> SassResult<Value>,
|
|
|
|
usize,
|
|
|
|
);
|
2020-04-03 23:47:56 -04:00
|
|
|
impl Builtin {
|
2020-04-04 18:17:04 -04:00
|
|
|
pub fn new(body: fn(CallArgs, &Scope, &Selector) -> SassResult<Value>) -> Builtin {
|
2020-04-03 23:47:56 -04:00
|
|
|
let count = FUNCTION_COUNT.fetch_add(1, Ordering::Relaxed);
|
|
|
|
Self(body, count)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for Builtin {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.1 == other.1
|
|
|
|
}
|
|
|
|
}
|
2020-01-25 20:58:30 -05:00
|
|
|
|
2020-04-30 15:00:57 -04:00
|
|
|
pub(crate) static GLOBAL_FUNCTIONS: Lazy<GlobalFunctionMap> = Lazy::new(|| {
|
2020-03-10 21:19:23 -04:00
|
|
|
let mut m = HashMap::new();
|
|
|
|
color::register(&mut m);
|
|
|
|
list::register(&mut m);
|
2020-03-30 15:43:15 -04:00
|
|
|
map::register(&mut m);
|
2020-03-10 21:19:23 -04:00
|
|
|
math::register(&mut m);
|
|
|
|
meta::register(&mut m);
|
|
|
|
string::register(&mut m);
|
|
|
|
m
|
|
|
|
});
|