#![allow(unused_imports, unused_variables, dead_code, unused_mut)] use std::collections::BTreeMap; use codemap::Spanned; use crate::{ args::CallArgs, atrule::Mixin, builtin::Builtin, common::Identifier, error::SassResult, parse::Parser, 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, mixins: BTreeMap, functions: BTreeMap, } impl Module { pub fn get_var(&self, name: Spanned) -> 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 { self.functions.get(&name).cloned() } pub fn insert_builtin( &mut self, name: &'static str, function: fn(CallArgs, &mut Parser<'_>) -> SassResult, ) { let ident = name.into(); self.functions .insert(ident, SassFunction::Builtin(Builtin::new(function), ident)); } } 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 }