store &'static str rather than String for builtin fn names
This commit is contained in:
parent
f2322dda4d
commit
2eef3e9f6a
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use num_traits::One;
|
use num_traits::One;
|
||||||
|
|
||||||
@ -8,9 +8,9 @@ use crate::common::QuoteKind;
|
|||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"hsl".to_owned(),
|
"hsl",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err(("Missing argument $channels.", args.span()).into());
|
return Err(("Missing argument $channels.", args.span()).into());
|
||||||
@ -218,7 +218,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"hsla".to_owned(),
|
"hsla",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err(("Missing argument $channels.", args.span()).into());
|
return Err(("Missing argument $channels.", args.span()).into());
|
||||||
@ -426,7 +426,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"hue".to_owned(),
|
"hue",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -440,7 +440,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"saturation".to_owned(),
|
"saturation",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -454,7 +454,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"lightness".to_owned(),
|
"lightness",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -468,7 +468,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"adjust-hue".to_owned(),
|
"adjust-hue",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -498,7 +498,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"lighten".to_owned(),
|
"lighten",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -528,7 +528,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"darken".to_owned(),
|
"darken",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -558,7 +558,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"saturate".to_owned(),
|
"saturate",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
@ -605,7 +605,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"desaturate".to_owned(),
|
"desaturate",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -635,7 +635,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"grayscale".to_owned(),
|
"grayscale",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -658,7 +658,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"complement".to_owned(),
|
"complement",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -675,7 +675,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"invert".to_owned(),
|
"invert",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let weight = match arg!(
|
let weight = match arg!(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ mod opacity;
|
|||||||
mod other;
|
mod other;
|
||||||
mod rgb;
|
mod rgb;
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
hsl::register(f);
|
hsl::register(f);
|
||||||
opacity::register(f);
|
opacity::register(f);
|
||||||
other::register(f);
|
other::register(f);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
use crate::common::QuoteKind;
|
use crate::common::QuoteKind;
|
||||||
@ -6,9 +6,9 @@ use crate::unit::Unit;
|
|||||||
use crate::value::Number;
|
use crate::value::Number;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"alpha".to_owned(),
|
"alpha",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -22,7 +22,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"opacity".to_owned(),
|
"opacity",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -40,7 +40,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"opacify".to_owned(),
|
"opacify",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -70,7 +70,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"fade-in".to_owned(),
|
"fade-in",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -100,7 +100,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"transparentize".to_owned(),
|
"transparentize",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -130,7 +130,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"fade-out".to_owned(),
|
"fade-out",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use num_traits::{One, Signed, Zero};
|
use num_traits::{One, Signed, Zero};
|
||||||
|
|
||||||
@ -50,8 +50,8 @@ macro_rules! opt_hsl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert("change-color".to_owned(), Builtin::new(|mut args, scope, super_selector| {
|
f.insert("change-color", Builtin::new(|mut args, scope, super_selector| {
|
||||||
if args.get_positional(1, scope, super_selector).is_some() {
|
if args.get_positional(1, scope, super_selector).is_some() {
|
||||||
return Err(
|
return Err(
|
||||||
("Only one positional argument is allowed. All other arguments must be passed by name.", args.span()
|
("Only one positional argument is allowed. All other arguments must be passed by name.", args.span()
|
||||||
@ -98,7 +98,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}))
|
}))
|
||||||
}));
|
}));
|
||||||
f.insert(
|
f.insert(
|
||||||
"adjust-color".to_owned(),
|
"adjust-color",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
@ -176,7 +176,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"scale-color".to_owned(),
|
"scale-color",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
let span = args.span();
|
let span = args.span();
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -266,7 +266,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"ie-hex-str".to_owned(),
|
"ie-hex-str",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let color = match arg!(args, scope, super_selector, 0, "color") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use num_traits::One;
|
use num_traits::One;
|
||||||
|
|
||||||
@ -8,9 +8,9 @@ use crate::common::QuoteKind;
|
|||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"rgb".to_owned(),
|
"rgb",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err(("Missing argument $channels.", args.span()).into());
|
return Err(("Missing argument $channels.", args.span()).into());
|
||||||
@ -337,7 +337,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"rgba".to_owned(),
|
"rgba",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Err(("Missing argument $channels.", args.span()).into());
|
return Err(("Missing argument $channels.", args.span()).into());
|
||||||
@ -664,7 +664,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"red".to_owned(),
|
"red",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -678,7 +678,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"green".to_owned(),
|
"green",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -692,7 +692,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"blue".to_owned(),
|
"blue",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
@ -706,7 +706,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"mix".to_owned(),
|
"mix",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(3)?;
|
args.max_args(3)?;
|
||||||
let color1 = match arg!(args, scope, super_selector, 0, "color1") {
|
let color1 = match arg!(args, scope, super_selector, 0, "color1") {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use num_traits::{One, Signed, ToPrimitive, Zero};
|
use num_traits::{One, Signed, ToPrimitive, Zero};
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ use crate::selector::Selector;
|
|||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
fn length(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
fn length(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let len = match arg!(args, scope, super_selector, 0, "list") {
|
let len = match arg!(args, scope, super_selector, 0, "list") {
|
||||||
@ -321,13 +321,13 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Ok(Value::List(result, ListSeparator::Comma, Brackets::None))
|
Ok(Value::List(result, ListSeparator::Comma, Brackets::None))
|
||||||
}
|
}
|
||||||
|
|
||||||
f.insert("length".to_owned(), Builtin::new(length));
|
f.insert("length", Builtin::new(length));
|
||||||
f.insert("nth".to_owned(), Builtin::new(nth));
|
f.insert("nth", Builtin::new(nth));
|
||||||
f.insert("list-separator".to_owned(), Builtin::new(list_separator));
|
f.insert("list-separator", Builtin::new(list_separator));
|
||||||
f.insert("set-nth".to_owned(), Builtin::new(set_nth));
|
f.insert("set-nth", Builtin::new(set_nth));
|
||||||
f.insert("append".to_owned(), Builtin::new(append));
|
f.insert("append", Builtin::new(append));
|
||||||
f.insert("join".to_owned(), Builtin::new(join));
|
f.insert("join", Builtin::new(join));
|
||||||
f.insert("is-bracketed".to_owned(), Builtin::new(is_bracketed));
|
f.insert("is-bracketed", Builtin::new(is_bracketed));
|
||||||
f.insert("index".to_owned(), Builtin::new(index));
|
f.insert("index", Builtin::new(index));
|
||||||
f.insert("zip".to_owned(), Builtin::new(zip));
|
f.insert("zip", Builtin::new(zip));
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
use crate::common::{Brackets, ListSeparator};
|
use crate::common::{Brackets, ListSeparator};
|
||||||
use crate::value::{SassMap, Value};
|
use crate::value::{SassMap, Value};
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-get".to_owned(),
|
"map-get",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let key = arg!(args, scope, super_selector, 1, "key");
|
let key = arg!(args, scope, super_selector, 1, "key");
|
||||||
@ -25,7 +25,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-has-key".to_owned(),
|
"map-has-key",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let key = arg!(args, scope, super_selector, 1, "key");
|
let key = arg!(args, scope, super_selector, 1, "key");
|
||||||
@ -44,7 +44,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-keys".to_owned(),
|
"map-keys",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let map = match arg!(args, scope, super_selector, 0, "map") {
|
let map = match arg!(args, scope, super_selector, 0, "map") {
|
||||||
@ -66,7 +66,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-values".to_owned(),
|
"map-values",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let map = match arg!(args, scope, super_selector, 0, "map") {
|
let map = match arg!(args, scope, super_selector, 0, "map") {
|
||||||
@ -88,7 +88,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-merge".to_owned(),
|
"map-merge",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let mut map1 = match arg!(args, scope, super_selector, 0, "map1") {
|
let mut map1 = match arg!(args, scope, super_selector, 0, "map1") {
|
||||||
@ -118,7 +118,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"map-remove".to_owned(),
|
"map-remove",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
let mut map = match arg!(args, scope, super_selector, 0, "map") {
|
let mut map = match arg!(args, scope, super_selector, 0, "map") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
#[cfg(feature = "random")]
|
#[cfg(feature = "random")]
|
||||||
use num_traits::{One, Signed, ToPrimitive, Zero};
|
use num_traits::{One, Signed, ToPrimitive, Zero};
|
||||||
@ -9,9 +9,9 @@ use super::Builtin;
|
|||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"percentage".to_owned(),
|
"percentage",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let num = match arg!(args, scope, super_selector, 0, "number") {
|
let num = match arg!(args, scope, super_selector, 0, "number") {
|
||||||
@ -41,7 +41,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"round".to_owned(),
|
"round",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
@ -58,7 +58,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"ceil".to_owned(),
|
"ceil",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
@ -75,7 +75,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"floor".to_owned(),
|
"floor",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
@ -92,7 +92,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"abs".to_owned(),
|
"abs",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
@ -109,7 +109,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"comparable".to_owned(),
|
"comparable",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let unit1 = match arg!(args, scope, super_selector, 0, "number1") {
|
let unit1 = match arg!(args, scope, super_selector, 0, "number1") {
|
||||||
@ -145,7 +145,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
// TODO: write tests for this. how?
|
// TODO: write tests for this. how?
|
||||||
#[cfg(feature = "random")]
|
#[cfg(feature = "random")]
|
||||||
f.insert(
|
f.insert(
|
||||||
"random".to_owned(),
|
"random",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let limit = match arg!(args, scope, super_selector, 0, "limit" = Value::Null) {
|
let limit = match arg!(args, scope, super_selector, 0, "limit" = Value::Null) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
|
|
||||||
@ -8,9 +8,9 @@ use crate::scope::global_var_exists;
|
|||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{SassFunction, Value};
|
use crate::value::{SassFunction, Value};
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"if".to_owned(),
|
"if",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(3)?;
|
args.max_args(3)?;
|
||||||
if arg!(args, scope, super_selector, 0, "condition").is_true(args.span())? {
|
if arg!(args, scope, super_selector, 0, "condition").is_true(args.span())? {
|
||||||
@ -21,7 +21,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"feature-exists".to_owned(),
|
"feature-exists",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "feature") {
|
match arg!(args, scope, super_selector, 0, "feature") {
|
||||||
@ -55,7 +55,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"unit".to_owned(),
|
"unit",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let unit = match arg!(args, scope, super_selector, 0, "number") {
|
let unit = match arg!(args, scope, super_selector, 0, "number") {
|
||||||
@ -75,7 +75,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"type-of".to_owned(),
|
"type-of",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
let value = arg!(args, scope, super_selector, 0, "value");
|
let value = arg!(args, scope, super_selector, 0, "value");
|
||||||
@ -86,7 +86,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"unitless".to_owned(),
|
"unitless",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
@ -97,7 +97,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"inspect".to_owned(),
|
"inspect",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
Ok(Value::Ident(
|
Ok(Value::Ident(
|
||||||
@ -107,7 +107,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"variable-exists".to_owned(),
|
"variable-exists",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "name") {
|
match arg!(args, scope, super_selector, 0, "name") {
|
||||||
@ -121,7 +121,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"global-variable-exists".to_owned(),
|
"global-variable-exists",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "name") {
|
match arg!(args, scope, super_selector, 0, "name") {
|
||||||
@ -135,7 +135,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"mixin-exists".to_owned(),
|
"mixin-exists",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
match arg!(args, scope, super_selector, 0, "name") {
|
match arg!(args, scope, super_selector, 0, "name") {
|
||||||
@ -149,12 +149,12 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"function-exists".to_owned(),
|
"function-exists",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
match arg!(args, scope, super_selector, 0, "name") {
|
match arg!(args, scope, super_selector, 0, "name") {
|
||||||
Value::Ident(s, _) => Ok(Value::bool(
|
Value::Ident(s, _) => Ok(Value::bool(
|
||||||
scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(&s),
|
scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(s.as_str()),
|
||||||
)),
|
)),
|
||||||
v => Err((
|
v => Err((
|
||||||
format!("$name: {} is not a string.", v.to_css_string(args.span())?),
|
format!("$name: {} is not a string.", v.to_css_string(args.span())?),
|
||||||
@ -165,7 +165,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"get-function".to_owned(),
|
"get-function",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(3)?;
|
args.max_args(3)?;
|
||||||
let name = match arg!(args, scope, super_selector, 0, "name") {
|
let name = match arg!(args, scope, super_selector, 0, "name") {
|
||||||
@ -208,7 +208,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
span: args.span(),
|
span: args.span(),
|
||||||
}) {
|
}) {
|
||||||
Ok(f) => SassFunction::UserDefined(Box::new(f), name),
|
Ok(f) => SassFunction::UserDefined(Box::new(f), name),
|
||||||
Err(..) => match GLOBAL_FUNCTIONS.get(&name) {
|
Err(..) => match GLOBAL_FUNCTIONS.get(name.as_str()) {
|
||||||
Some(f) => SassFunction::Builtin(f.clone(), name),
|
Some(f) => SassFunction::Builtin(f.clone(), name),
|
||||||
None => {
|
None => {
|
||||||
return Err((format!("Function not found: {}", name), args.span()).into())
|
return Err((format!("Function not found: {}", name), args.span()).into())
|
||||||
@ -220,7 +220,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"call".to_owned(),
|
"call",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
let func = match arg!(args, scope, super_selector, 0, "function") {
|
let func = match arg!(args, scope, super_selector, 0, "function") {
|
||||||
Value::Function(f) => f,
|
Value::Function(f) => f,
|
||||||
|
@ -19,6 +19,8 @@ mod meta;
|
|||||||
mod selector;
|
mod selector;
|
||||||
mod string;
|
mod string;
|
||||||
|
|
||||||
|
pub(crate) type GlobalFunctionMap = HashMap<&'static str, Builtin>;
|
||||||
|
|
||||||
static FUNCTION_COUNT: AtomicUsize = AtomicUsize::new(0);
|
static FUNCTION_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
// TODO: impl Fn
|
// TODO: impl Fn
|
||||||
@ -40,7 +42,7 @@ impl PartialEq for Builtin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) static GLOBAL_FUNCTIONS: Lazy<HashMap<String, Builtin>> = Lazy::new(|| {
|
pub(crate) static GLOBAL_FUNCTIONS: Lazy<GlobalFunctionMap> = Lazy::new(|| {
|
||||||
let mut m = HashMap::new();
|
let mut m = HashMap::new();
|
||||||
color::register(&mut m);
|
color::register(&mut m);
|
||||||
list::register(&mut m);
|
list::register(&mut m);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use super::GlobalFunctionMap;
|
||||||
|
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
use num_traits::{Signed, ToPrimitive, Zero};
|
use num_traits::{Signed, ToPrimitive, Zero};
|
||||||
@ -11,9 +11,9 @@ use crate::common::QuoteKind;
|
|||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut GlobalFunctionMap) {
|
||||||
f.insert(
|
f.insert(
|
||||||
"to-upper-case".to_owned(),
|
"to-upper-case",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -30,7 +30,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"to-lower-case".to_owned(),
|
"to-lower-case",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -47,7 +47,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-length".to_owned(),
|
"str-length",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -67,7 +67,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"quote".to_owned(),
|
"quote",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -84,7 +84,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"unquote".to_owned(),
|
"unquote",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -101,7 +101,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-slice".to_owned(),
|
"str-slice",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(3)?;
|
args.max_args(3)?;
|
||||||
let (string, quotes) = match arg!(args, scope, super_selector, 0, "string") {
|
let (string, quotes) = match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -205,7 +205,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-index".to_owned(),
|
"str-index",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(2)?;
|
args.max_args(2)?;
|
||||||
let s1 = match arg!(args, scope, super_selector, 0, "string") {
|
let s1 = match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -243,7 +243,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
"str-insert".to_owned(),
|
"str-insert",
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
args.max_args(3)?;
|
args.max_args(3)?;
|
||||||
let (s1, quotes) = match arg!(args, scope, super_selector, 0, "string") {
|
let (s1, quotes) = match arg!(args, scope, super_selector, 0, "string") {
|
||||||
@ -347,7 +347,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
);
|
);
|
||||||
#[cfg(feature = "random")]
|
#[cfg(feature = "random")]
|
||||||
f.insert(
|
f.insert(
|
||||||
"unique-id".to_owned(),
|
"unique-id",
|
||||||
Builtin::new(|args, _, _| {
|
Builtin::new(|args, _, _| {
|
||||||
args.max_args(0)?;
|
args.max_args(0)?;
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -519,7 +519,7 @@ impl Value {
|
|||||||
span,
|
span,
|
||||||
}) {
|
}) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(_) => match GLOBAL_FUNCTIONS.get(&s.replace('_', "-")) {
|
Err(_) => match GLOBAL_FUNCTIONS.get(s.replace('_', "-").as_str()) {
|
||||||
Some(f) => {
|
Some(f) => {
|
||||||
return Ok(IntermediateValue::Value(Spanned {
|
return Ok(IntermediateValue::Value(Spanned {
|
||||||
node: f.0(eat_call_args(toks)?, scope, super_selector)?,
|
node: f.0(eat_call_args(toks)?, scope, super_selector)?,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user