diff --git a/src/builtin/functions/list.rs b/src/builtin/functions/list.rs index 9dbb483..c0b8550 100644 --- a/src/builtin/functions/list.rs +++ b/src/builtin/functions/list.rs @@ -11,7 +11,7 @@ use crate::{ value::{Number, Value}, }; -fn length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; Ok(Value::Dimension( Number::from(args.get_err(0, "list")?.as_list().len()), @@ -20,7 +20,7 @@ fn length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { )) } -fn nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(2)?; let mut list = args.get_err(0, "list")?.as_list(); let n = match args.get_err(1, "n")? { @@ -61,7 +61,7 @@ fn nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { })) } -fn list_separator(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn list_separator(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; Ok(Value::String( match args.get_err(0, "list")? { @@ -73,7 +73,7 @@ fn list_separator(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult) -> SassResult { +pub(crate) fn set_nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(3)?; let (mut list, sep, brackets) = match args.get_err(0, "list")? { Value::List(v, sep, b) => (v, sep, b), @@ -120,7 +120,7 @@ fn set_nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { Ok(Value::List(list, sep, brackets)) } -fn append(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn append(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(3)?; let (mut list, sep, brackets) = match args.get_err(0, "list")? { Value::List(v, sep, b) => (v, sep, b), @@ -158,7 +158,7 @@ fn append(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { Ok(Value::List(list, sep, brackets)) } -fn join(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn join(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(4)?; let (mut list1, sep1, brackets) = match args.get_err(0, "list1")? { Value::List(v, sep, brackets) => (v, sep, brackets), @@ -225,7 +225,7 @@ fn join(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { Ok(Value::List(list1, sep, brackets)) } -fn is_bracketed(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn is_bracketed(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; Ok(Value::bool(match args.get_err(0, "list")? { Value::List(.., brackets) => match brackets { @@ -236,7 +236,7 @@ fn is_bracketed(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult) -> SassResult { +pub(crate) fn index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(2)?; let list = args.get_err(0, "list")?.as_list(); let value = args.get_err(1, "value")?; @@ -247,7 +247,7 @@ fn index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { Ok(Value::Dimension(index, Unit::None, true)) } -fn zip(args: CallArgs, parser: &mut Parser<'_>) -> SassResult { +pub(crate) fn zip(args: CallArgs, parser: &mut Parser<'_>) -> SassResult { let lists = args .get_variadic()? .into_iter() diff --git a/src/builtin/mod.rs b/src/builtin/mod.rs index e1b3d41..ccef78d 100644 --- a/src/builtin/mod.rs +++ b/src/builtin/mod.rs @@ -1,4 +1,4 @@ mod functions; pub(crate) mod modules; -pub(crate) use functions::{math, meta, selector, Builtin, GLOBAL_FUNCTIONS}; +pub(crate) use functions::{list, math, meta, selector, Builtin, GLOBAL_FUNCTIONS}; diff --git a/src/builtin/modules/list.rs b/src/builtin/modules/list.rs index 47d58dc..ddd6611 100644 --- a/src/builtin/modules/list.rs +++ b/src/builtin/modules/list.rs @@ -1,5 +1,22 @@ use crate::{ - args::CallArgs, builtin::modules::Module, error::SassResult, parse::Parser, value::Value, + args::CallArgs, + builtin::{ + list::{append, index, is_bracketed, join, length, list_separator, nth, set_nth, zip}, + modules::Module, + }, + error::SassResult, + parse::Parser, + value::Value, }; -pub(crate) fn declare(_f: &mut Module) {} +pub(crate) fn declare(f: &mut Module) { + f.insert_builtin("append", append); + f.insert_builtin("index", index); + f.insert_builtin("is-bracketed", is_bracketed); + f.insert_builtin("join", join); + f.insert_builtin("length", length); + f.insert_builtin("separator", list_separator); + f.insert_builtin("nth", nth); + f.insert_builtin("set-nth", set_nth); + f.insert_builtin("zip", zip); +}