builtin functions take args by value
This commit is contained in:
parent
39031aefff
commit
8e3e23c6cd
@ -60,7 +60,7 @@ impl CallArgs {
|
|||||||
self.0.get(&CallArg::Positional(val))
|
self.0.get(&CallArg::Positional(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_variadic(self) -> SassResult<Value> {
|
pub fn get_variadic(self) -> SassResult<Vec<Value>> {
|
||||||
let mut vals = Vec::new();
|
let mut vals = Vec::new();
|
||||||
let mut args = self
|
let mut args = self
|
||||||
.0
|
.0
|
||||||
@ -71,7 +71,7 @@ impl CallArgs {
|
|||||||
for arg in args {
|
for arg in args {
|
||||||
vals.push(arg.1);
|
vals.push(arg.1);
|
||||||
}
|
}
|
||||||
Ok(Value::ArgList(vals))
|
Ok(vals)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
|
@ -46,7 +46,8 @@ impl Function {
|
|||||||
pub fn args(mut self, mut args: CallArgs) -> SassResult<Function> {
|
pub fn args(mut self, mut args: CallArgs) -> SassResult<Function> {
|
||||||
for (idx, arg) in self.args.0.iter().enumerate() {
|
for (idx, arg) in self.args.0.iter().enumerate() {
|
||||||
if arg.is_variadic {
|
if arg.is_variadic {
|
||||||
self.scope.insert_var(&arg.name, args.get_variadic()?)?;
|
self.scope
|
||||||
|
.insert_var(&arg.name, Value::ArgList(args.get_variadic()?))?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let val = match args.remove_positional(idx) {
|
let val = match args.remove_positional(idx) {
|
||||||
|
@ -11,6 +11,7 @@ use crate::selector::Selector;
|
|||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
devour_whitespace, devour_whitespace_or_comment, eat_ident, read_until_closing_curly_brace,
|
devour_whitespace, devour_whitespace_or_comment, eat_ident, read_until_closing_curly_brace,
|
||||||
};
|
};
|
||||||
|
use crate::value::Value;
|
||||||
use crate::{eat_expr, Expr, RuleSet, Stmt, Token};
|
use crate::{eat_expr, Expr, RuleSet, Stmt, Token};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -62,7 +63,8 @@ impl Mixin {
|
|||||||
pub fn args(mut self, mut args: CallArgs) -> SassResult<Mixin> {
|
pub fn args(mut self, mut args: CallArgs) -> SassResult<Mixin> {
|
||||||
for (idx, arg) in self.args.0.iter().enumerate() {
|
for (idx, arg) in self.args.0.iter().enumerate() {
|
||||||
if arg.is_variadic {
|
if arg.is_variadic {
|
||||||
self.scope.insert_var(&arg.name, args.get_variadic()?)?;
|
self.scope
|
||||||
|
.insert_var(&arg.name, Value::ArgList(args.get_variadic()?))?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let val = match args.remove_positional(idx) {
|
let val = match args.remove_positional(idx) {
|
||||||
|
@ -11,7 +11,7 @@ use crate::value::{Number, Value};
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"hsl".to_owned(),
|
"hsl".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err("Missing argument $channels.".into());
|
return Err("Missing argument $channels.".into());
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"hsla".to_owned(),
|
"hsla".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err("Missing argument $channels.".into());
|
return Err("Missing argument $channels.".into());
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"hue".to_owned(),
|
"hue".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
|
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
|
||||||
@ -177,7 +177,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"saturation".to_owned(),
|
"saturation".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
|
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
|
||||||
@ -187,7 +187,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"lightness".to_owned(),
|
"lightness".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
|
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
|
||||||
@ -197,7 +197,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"adjust-hue".to_owned(),
|
"adjust-hue".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -212,7 +212,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"lighten".to_owned(),
|
"lighten".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -227,7 +227,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"darken".to_owned(),
|
"darken".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -242,7 +242,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"saturate".to_owned(),
|
"saturate".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
return Ok(Value::Ident(
|
return Ok(Value::Ident(
|
||||||
@ -270,7 +270,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"desaturate".to_owned(),
|
"desaturate".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -285,7 +285,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"grayscale".to_owned(),
|
"grayscale".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -302,7 +302,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"complement".to_owned(),
|
"complement".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -313,7 +313,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"invert".to_owned(),
|
"invert".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let weight = match arg!(
|
let weight = match arg!(
|
||||||
args,
|
args,
|
||||||
|
@ -9,7 +9,7 @@ use crate::value::Value;
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"alpha".to_owned(),
|
"alpha".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
@ -19,7 +19,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"opacity".to_owned(),
|
"opacity".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
@ -33,7 +33,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"opacify".to_owned(),
|
"opacify".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -48,7 +48,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"fade-in".to_owned(),
|
"fade-in".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -63,7 +63,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"transparentize".to_owned(),
|
"transparentize".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -78,7 +78,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"fade-out".to_owned(),
|
"fade-out".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
|
@ -31,7 +31,7 @@ macro_rules! opt_hsl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert("change-color".to_owned(), Box::new(|args, _| {
|
f.insert("change-color".to_owned(), Box::new(|mut args, _| {
|
||||||
if args.get_positional(1).is_some() {
|
if args.get_positional(1).is_some() {
|
||||||
return Err("Only one positional argument is allowed. All other arguments must be passed by name.".into());
|
return Err("Only one positional argument is allowed. All other arguments must be passed by name.".into());
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}));
|
}));
|
||||||
f.insert(
|
f.insert(
|
||||||
"adjust-color".to_owned(),
|
"adjust-color".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -123,7 +123,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"scale-color".to_owned(),
|
"scale-color".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -209,7 +209,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"ie-hex-str".to_owned(),
|
"ie-hex-str".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let color = match arg!(args, 0, "color") {
|
let color = match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
|
@ -10,7 +10,7 @@ use crate::value::{Number, Value};
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"rgb".to_owned(),
|
"rgb".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err("Missing argument $channels.".into());
|
return Err("Missing argument $channels.".into());
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"rgba".to_owned(),
|
"rgba".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err("Missing argument $channels.".into());
|
return Err("Missing argument $channels.".into());
|
||||||
}
|
}
|
||||||
@ -254,7 +254,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"red".to_owned(),
|
"red".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
|
||||||
@ -264,7 +264,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"green".to_owned(),
|
"green".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
|
||||||
@ -274,7 +274,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"blue".to_owned(),
|
"blue".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
|
||||||
@ -284,7 +284,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"mix".to_owned(),
|
"mix".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 3);
|
max_args!(args, 3);
|
||||||
let color1 = match arg!(args, 0, "color1") {
|
let color1 = match arg!(args, 0, "color1") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
|
@ -10,7 +10,7 @@ use crate::value::{Number, Value};
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"length".to_owned(),
|
"length".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let len = match arg!(args, 0, "list") {
|
let len = match arg!(args, 0, "list") {
|
||||||
Value::List(v, ..) => Number::from(v.len()),
|
Value::List(v, ..) => Number::from(v.len()),
|
||||||
@ -22,7 +22,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"nth".to_owned(),
|
"nth".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let list = match arg!(args, 0, "list") {
|
let list = match arg!(args, 0, "list") {
|
||||||
Value::List(v, ..) => v,
|
Value::List(v, ..) => v,
|
||||||
@ -59,7 +59,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"list-separator".to_owned(),
|
"list-separator".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
Ok(Value::Ident(
|
Ok(Value::Ident(
|
||||||
match arg!(args, 0, "list") {
|
match arg!(args, 0, "list") {
|
||||||
@ -73,7 +73,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"set-nth".to_owned(),
|
"set-nth".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 3);
|
max_args!(args, 3);
|
||||||
let (mut list, sep) = match arg!(args, 0, "list") {
|
let (mut list, sep) = match arg!(args, 0, "list") {
|
||||||
Value::List(v, sep, ..) => (v, sep),
|
Value::List(v, sep, ..) => (v, sep),
|
||||||
@ -113,7 +113,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"append".to_owned(),
|
"append".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 3);
|
max_args!(args, 3);
|
||||||
let (mut list, sep) = match arg!(args, 0, "list") {
|
let (mut list, sep) = match arg!(args, 0, "list") {
|
||||||
Value::List(v, sep, ..) => (v, sep),
|
Value::List(v, sep, ..) => (v, sep),
|
||||||
@ -143,7 +143,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"join".to_owned(),
|
"join".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 3);
|
max_args!(args, 3);
|
||||||
let (mut list1, sep1, brackets) = match arg!(args, 0, "list") {
|
let (mut list1, sep1, brackets) = match arg!(args, 0, "list") {
|
||||||
Value::List(v, sep, brackets) => (v, sep, brackets),
|
Value::List(v, sep, brackets) => (v, sep, brackets),
|
||||||
@ -182,7 +182,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"is-bracketed".to_owned(),
|
"is-bracketed".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
Ok(Value::bool(match arg!(args, 0, "list") {
|
Ok(Value::bool(match arg!(args, 0, "list") {
|
||||||
Value::List(.., brackets) => match brackets {
|
Value::List(.., brackets) => match brackets {
|
||||||
|
@ -7,7 +7,7 @@ use crate::value::{SassMap, Value};
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-get".to_owned(),
|
"map-get".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let key = arg!(args, 1, "key");
|
let key = arg!(args, 1, "key");
|
||||||
let map = match arg!(args, 0, "map") {
|
let map = match arg!(args, 0, "map") {
|
||||||
@ -20,7 +20,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-has-key".to_owned(),
|
"map-has-key".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let key = arg!(args, 1, "key");
|
let key = arg!(args, 1, "key");
|
||||||
let map = match arg!(args, 0, "map") {
|
let map = match arg!(args, 0, "map") {
|
||||||
@ -33,7 +33,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-keys".to_owned(),
|
"map-keys".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let map = match arg!(args, 0, "map") {
|
let map = match arg!(args, 0, "map") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
@ -49,7 +49,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-values".to_owned(),
|
"map-values".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let map = match arg!(args, 0, "map") {
|
let map = match arg!(args, 0, "map") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
@ -65,7 +65,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-merge".to_owned(),
|
"map-merge".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let mut map1 = match arg!(args, 0, "map1") {
|
let mut map1 = match arg!(args, 0, "map1") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
|
@ -7,7 +7,7 @@ use crate::value::{Number, Value};
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"percentage".to_owned(),
|
"percentage".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let num = match arg!(args, 0, "number") {
|
let num = match arg!(args, 0, "number") {
|
||||||
Value::Dimension(n, Unit::None) => n * Number::from(100),
|
Value::Dimension(n, Unit::None) => n * Number::from(100),
|
||||||
@ -21,7 +21,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"round".to_owned(),
|
"round".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "number") {
|
match arg!(args, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.round(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.round(), u)),
|
||||||
@ -31,7 +31,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"ceil".to_owned(),
|
"ceil".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "number") {
|
match arg!(args, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.ceil(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.ceil(), u)),
|
||||||
@ -41,7 +41,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"floor".to_owned(),
|
"floor".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "number") {
|
match arg!(args, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.floor(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.floor(), u)),
|
||||||
@ -51,7 +51,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"abs".to_owned(),
|
"abs".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "number") {
|
match arg!(args, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.abs(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.abs(), u)),
|
||||||
@ -61,7 +61,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"comparable".to_owned(),
|
"comparable".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let unit1 = match arg!(args, 0, "number1") {
|
let unit1 = match arg!(args, 0, "number1") {
|
||||||
Value::Dimension(_, u) => u,
|
Value::Dimension(_, u) => u,
|
||||||
|
@ -9,7 +9,7 @@ use crate::value::Value;
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"if".to_owned(),
|
"if".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 3);
|
max_args!(args, 3);
|
||||||
if arg!(args, 0, "condition").is_true()? {
|
if arg!(args, 0, "condition").is_true()? {
|
||||||
Ok(arg!(args, 1, "if-true"))
|
Ok(arg!(args, 1, "if-true"))
|
||||||
@ -20,7 +20,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"feature-exists".to_owned(),
|
"feature-exists".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "feature") {
|
match arg!(args, 0, "feature") {
|
||||||
Value::Ident(s, _) => match s.as_str() {
|
Value::Ident(s, _) => match s.as_str() {
|
||||||
@ -47,7 +47,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"unit".to_owned(),
|
"unit".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let unit = match arg!(args, 0, "number") {
|
let unit = match arg!(args, 0, "number") {
|
||||||
Value::Dimension(_, u) => u.to_string(),
|
Value::Dimension(_, u) => u.to_string(),
|
||||||
@ -58,7 +58,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"type-of".to_owned(),
|
"type-of".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
let value = arg!(args, 0, "value");
|
let value = arg!(args, 0, "value");
|
||||||
Ok(Value::Ident(value.kind()?.to_owned(), QuoteKind::None))
|
Ok(Value::Ident(value.kind()?.to_owned(), QuoteKind::None))
|
||||||
@ -66,7 +66,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"unitless".to_owned(),
|
"unitless".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "number") {
|
match arg!(args, 0, "number") {
|
||||||
Value::Dimension(_, Unit::None) => Ok(Value::True),
|
Value::Dimension(_, Unit::None) => Ok(Value::True),
|
||||||
@ -77,7 +77,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"inspect".to_owned(),
|
"inspect".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
Ok(Value::Ident(
|
Ok(Value::Ident(
|
||||||
match arg!(args, 0, "value") {
|
match arg!(args, 0, "value") {
|
||||||
@ -90,7 +90,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"variable-exists".to_owned(),
|
"variable-exists".to_owned(),
|
||||||
Box::new(|args, scope| {
|
Box::new(|mut args, scope| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "name") {
|
match arg!(args, 0, "name") {
|
||||||
Value::Ident(s, _) => Ok(Value::bool(scope.var_exists(&s))),
|
Value::Ident(s, _) => Ok(Value::bool(scope.var_exists(&s))),
|
||||||
@ -100,7 +100,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"global-variable-exists".to_owned(),
|
"global-variable-exists".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "name") {
|
match arg!(args, 0, "name") {
|
||||||
Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))),
|
Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))),
|
||||||
@ -110,7 +110,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"mixin-exists".to_owned(),
|
"mixin-exists".to_owned(),
|
||||||
Box::new(|args, scope| {
|
Box::new(|mut args, scope| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
match arg!(args, 0, "name") {
|
match arg!(args, 0, "name") {
|
||||||
Value::Ident(s, _) => Ok(Value::bool(scope.mixin_exists(&s))),
|
Value::Ident(s, _) => Ok(Value::bool(scope.mixin_exists(&s))),
|
||||||
@ -120,7 +120,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"function-exists".to_owned(),
|
"function-exists".to_owned(),
|
||||||
Box::new(|args, scope| {
|
Box::new(|mut args, scope| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
match arg!(args, 0, "name") {
|
match arg!(args, 0, "name") {
|
||||||
Value::Ident(s, _) => Ok(Value::bool(
|
Value::Ident(s, _) => Ok(Value::bool(
|
||||||
|
@ -17,7 +17,7 @@ mod meta;
|
|||||||
mod selector;
|
mod selector;
|
||||||
mod string;
|
mod string;
|
||||||
|
|
||||||
pub(crate) type Builtin = Box<dyn Fn(&mut CallArgs, &Scope) -> SassResult<Value> + Send + Sync>;
|
pub(crate) type Builtin = Box<dyn Fn(CallArgs, &Scope) -> SassResult<Value> + Send + Sync>;
|
||||||
|
|
||||||
pub(crate) static GLOBAL_FUNCTIONS: Lazy<HashMap<String, Builtin>> = Lazy::new(|| {
|
pub(crate) static GLOBAL_FUNCTIONS: Lazy<HashMap<String, Builtin>> = Lazy::new(|| {
|
||||||
let mut m = HashMap::new();
|
let mut m = HashMap::new();
|
||||||
|
@ -11,7 +11,7 @@ use crate::value::{Number, Value};
|
|||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"to-upper-case".to_owned(),
|
"to-upper-case".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "string") {
|
match arg!(args, 0, "string") {
|
||||||
Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_uppercase(), q)),
|
Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_uppercase(), q)),
|
||||||
@ -21,7 +21,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"to-lower-case".to_owned(),
|
"to-lower-case".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "string") {
|
match arg!(args, 0, "string") {
|
||||||
Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_lowercase(), q)),
|
Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_lowercase(), q)),
|
||||||
@ -31,7 +31,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-length".to_owned(),
|
"str-length".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "string") {
|
match arg!(args, 0, "string") {
|
||||||
Value::Ident(i, _) => Ok(Value::Dimension(
|
Value::Ident(i, _) => Ok(Value::Dimension(
|
||||||
@ -44,7 +44,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"quote".to_owned(),
|
"quote".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "string") {
|
match arg!(args, 0, "string") {
|
||||||
Value::Ident(i, _) => Ok(Value::Ident(i, QuoteKind::Double)),
|
Value::Ident(i, _) => Ok(Value::Ident(i, QuoteKind::Double)),
|
||||||
@ -54,7 +54,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"unquote".to_owned(),
|
"unquote".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 1);
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "string") {
|
match arg!(args, 0, "string") {
|
||||||
i @ Value::Ident(..) => Ok(i.unquote()),
|
i @ Value::Ident(..) => Ok(i.unquote()),
|
||||||
@ -64,7 +64,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-slice".to_owned(),
|
"str-slice".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 3);
|
max_args!(args, 3);
|
||||||
let (string, quotes) = match arg!(args, 0, "string") {
|
let (string, quotes) = match arg!(args, 0, "string") {
|
||||||
Value::Ident(s, q) => (s, q),
|
Value::Ident(s, q) => (s, q),
|
||||||
@ -127,7 +127,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-index".to_owned(),
|
"str-index".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 2);
|
max_args!(args, 2);
|
||||||
let s1 = match arg!(args, 0, "string") {
|
let s1 = match arg!(args, 0, "string") {
|
||||||
Value::Ident(i, _) => i,
|
Value::Ident(i, _) => i,
|
||||||
@ -147,7 +147,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-insert".to_owned(),
|
"str-insert".to_owned(),
|
||||||
Box::new(|args, _| {
|
Box::new(|mut args, _| {
|
||||||
max_args!(args, 3);
|
max_args!(args, 3);
|
||||||
let (s1, quotes) = match arg!(args, 0, "string") {
|
let (s1, quotes) = match arg!(args, 0, "string") {
|
||||||
Value::Ident(i, q) => (i, q.normalize()),
|
Value::Ident(i, q) => (i, q.normalize()),
|
||||||
|
@ -367,7 +367,7 @@ impl Value {
|
|||||||
Err(_) => match GLOBAL_FUNCTIONS.get(&s) {
|
Err(_) => match GLOBAL_FUNCTIONS.get(&s) {
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
return Ok(IntermediateValue::Value(f(
|
return Ok(IntermediateValue::Value(f(
|
||||||
&mut eat_call_args(toks, scope, super_selector)?,
|
eat_call_args(toks, scope, super_selector)?,
|
||||||
scope,
|
scope,
|
||||||
)?))
|
)?))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user