diff --git a/src/builtin/functions/meta.rs b/src/builtin/functions/meta.rs index c4b9b4f..d6e3fd9 100644 --- a/src/builtin/functions/meta.rs +++ b/src/builtin/functions/meta.rs @@ -20,7 +20,7 @@ fn if_(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { } } -fn feature_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn feature_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; match args.get_err(0, "feature")? { #[allow(clippy::match_same_arms)] @@ -65,7 +65,7 @@ pub(crate) fn unit(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult) -> SassResult { +pub(crate) fn type_of(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; let value = args.get_err(0, "value")?; Ok(Value::String(value.kind().to_owned(), QuoteKind::None)) @@ -81,7 +81,7 @@ pub(crate) fn unitless(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResul }) } -fn inspect(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn inspect(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; Ok(Value::String( args.get_err(0, "value")?.inspect(args.span())?.into_owned(), @@ -89,7 +89,7 @@ fn inspect(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { )) } -fn variable_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn variable_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; match args.get_err(0, "name")? { Value::String(s, _) => Ok(Value::bool( @@ -103,7 +103,10 @@ fn variable_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult) -> SassResult { +pub(crate) fn global_variable_exists( + mut args: CallArgs, + parser: &mut Parser<'_>, +) -> SassResult { args.max_args(1)?; match args.get_err(0, "name")? { Value::String(s, _) => Ok(Value::bool(parser.global_scope.var_exists(s.into()))), @@ -115,7 +118,8 @@ fn global_variable_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassRe } } -fn mixin_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +// todo: should check for module arg (as well as several others) +pub(crate) fn mixin_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(2)?; match args.get_err(0, "name")? { Value::String(s, _) => Ok(Value::bool( @@ -129,7 +133,7 @@ fn mixin_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult) -> SassResult { +pub(crate) fn function_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(2)?; match args.get_err(0, "name")? { Value::String(s, _) => Ok(Value::bool( @@ -143,7 +147,7 @@ fn function_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult) -> SassResult { +pub(crate) fn get_function(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(3)?; let name: Identifier = match args.get_err(0, "name")? { Value::String(s, _) => s.into(), @@ -193,7 +197,7 @@ fn get_function(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult) -> SassResult { +pub(crate) fn call(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { let func = match args.get_err(0, "function")? { Value::FunctionRef(f) => f, v => { @@ -211,7 +215,7 @@ fn call(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { } #[allow(clippy::needless_pass_by_value)] -fn content_exists(args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn content_exists(args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(0)?; if !parser.flags.in_mixin() { return Err(( @@ -225,6 +229,12 @@ fn content_exists(args: CallArgs, parser: &mut Parser<'_>) -> SassResult )) } +#[allow(dead_code, unused_mut, unused_variables)] +pub(crate) fn keywords(args: CallArgs, parser: &mut Parser<'_>) -> SassResult { + args.max_args(1)?; + todo!("builtin function `keywords` blocked on better handling of call args") +} + pub(crate) fn declare(f: &mut GlobalFunctionMap) { f.insert("if", Builtin::new(if_)); f.insert("feature-exists", Builtin::new(feature_exists)); @@ -242,4 +252,5 @@ pub(crate) fn declare(f: &mut GlobalFunctionMap) { f.insert("get-function", Builtin::new(get_function)); f.insert("call", Builtin::new(call)); f.insert("content-exists", Builtin::new(content_exists)); + f.insert("keywords", Builtin::new(keywords)); } diff --git a/src/builtin/modules/meta.rs b/src/builtin/modules/meta.rs index 47d58dc..be4a626 100644 --- a/src/builtin/modules/meta.rs +++ b/src/builtin/modules/meta.rs @@ -1,5 +1,42 @@ use crate::{ - args::CallArgs, builtin::modules::Module, error::SassResult, parse::Parser, value::Value, + args::CallArgs, + builtin::{ + meta::{ + call, content_exists, feature_exists, function_exists, get_function, + global_variable_exists, inspect, keywords, mixin_exists, type_of, variable_exists, + }, + modules::Module, + }, + error::SassResult, + parse::Parser, + value::Value, }; -pub(crate) fn declare(_f: &mut Module) {} +fn load_css(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { + args.max_args(2)?; + todo!() +} + +fn module_functions(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { + args.max_args(2)?; + todo!() +} + +fn module_variables(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { + args.max_args(2)?; + todo!() +} + +pub(crate) fn declare(f: &mut Module) { + f.insert_builtin("call", call); + f.insert_builtin("content-exists", content_exists); + f.insert_builtin("feature-exists", feature_exists); + f.insert_builtin("function-exists", function_exists); + f.insert_builtin("get-function", get_function); + f.insert_builtin("global-variable-exists", global_variable_exists); + f.insert_builtin("inspect", inspect); + f.insert_builtin("keywords", keywords); + f.insert_builtin("mixin-exists", mixin_exists); + f.insert_builtin("type-of", type_of); + f.insert_builtin("variable-exists", variable_exists); +}