2020-07-26 00:05:13 -04:00
|
|
|
#![allow(unused_imports, unused_variables, dead_code, unused_mut)]
|
|
|
|
|
2020-07-25 20:05:46 -04:00
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
2020-07-26 00:05:13 -04:00
|
|
|
use codemap::Spanned;
|
|
|
|
|
2020-07-25 20:05:46 -04:00
|
|
|
use crate::{
|
2020-07-26 00:05:13 -04:00
|
|
|
args::CallArgs,
|
2020-07-25 20:05:46 -04:00
|
|
|
atrule::Mixin,
|
2020-07-26 00:05:13 -04:00
|
|
|
builtin::Builtin,
|
2020-07-25 20:05:46 -04:00
|
|
|
common::Identifier,
|
2020-07-26 00:05:13 -04:00
|
|
|
error::SassResult,
|
|
|
|
parse::Parser,
|
2020-07-25 20:05:46 -04:00
|
|
|
value::{SassFunction, Value},
|
|
|
|
};
|
|
|
|
|
|
|
|
mod color;
|
|
|
|
mod list;
|
|
|
|
mod map;
|
|
|
|
mod math;
|
|
|
|
mod meta;
|
|
|
|
mod selector;
|
|
|
|
mod string;
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub(crate) struct Module {
|
|
|
|
vars: BTreeMap<Identifier, Value>,
|
|
|
|
mixins: BTreeMap<Identifier, Mixin>,
|
|
|
|
functions: BTreeMap<Identifier, SassFunction>,
|
|
|
|
}
|
|
|
|
|
2020-07-26 00:05:13 -04:00
|
|
|
impl Module {
|
|
|
|
pub fn get_var(&self, name: Spanned<Identifier>) -> SassResult<&Value> {
|
|
|
|
match self.vars.get(&name.node) {
|
|
|
|
Some(v) => Ok(&v),
|
|
|
|
None => Err(("Undefined variable.", name.span).into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_fn(&self, name: Identifier) -> Option<SassFunction> {
|
|
|
|
self.functions.get(&name).cloned()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn insert_builtin(
|
|
|
|
&mut self,
|
|
|
|
name: &'static str,
|
|
|
|
function: fn(CallArgs, &mut Parser<'_>) -> SassResult<Value>,
|
|
|
|
) {
|
|
|
|
let ident = name.into();
|
|
|
|
self.functions
|
|
|
|
.insert(ident, SassFunction::Builtin(Builtin::new(function), ident));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 20:05:46 -04:00
|
|
|
pub(crate) fn declare_module_color() -> Module {
|
|
|
|
let mut module = Module::default();
|
|
|
|
color::declare(&mut module);
|
|
|
|
module
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn declare_module_list() -> Module {
|
|
|
|
let mut module = Module::default();
|
|
|
|
list::declare(&mut module);
|
|
|
|
module
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn declare_module_map() -> Module {
|
|
|
|
let mut module = Module::default();
|
|
|
|
map::declare(&mut module);
|
|
|
|
module
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn declare_module_math() -> Module {
|
|
|
|
let mut module = Module::default();
|
|
|
|
math::declare(&mut module);
|
|
|
|
module
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn declare_module_meta() -> Module {
|
|
|
|
let mut module = Module::default();
|
|
|
|
meta::declare(&mut module);
|
|
|
|
module
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn declare_module_selector() -> Module {
|
|
|
|
let mut module = Module::default();
|
|
|
|
selector::declare(&mut module);
|
|
|
|
module
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn declare_module_string() -> Module {
|
|
|
|
let mut module = Module::default();
|
|
|
|
string::declare(&mut module);
|
|
|
|
module
|
|
|
|
}
|