replace max_args! macro with builtin method

This commit is contained in:
ConnorSkees 2020-04-22 06:17:52 -04:00
parent 4d989b60b1
commit 680790c49a
11 changed files with 83 additions and 81 deletions

View File

@ -170,6 +170,27 @@ impl CallArgs {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn max_args(&self, max: usize) -> SassResult<()> {
let len = self.len();
if len > max {
let mut err = String::with_capacity(50);
err.push_str(&format!("Only {} argument", max));
if max != 1 {
err.push('s');
}
err.push_str(" allowed, but ");
err.push_str(&len.to_string());
err.push(' ');
if len == 1 {
err.push_str("was passed.")
} else {
err.push_str("were passed.")
}
return Err((err, self.span()).into());
}
Ok(())
}
}
pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(

View File

@ -428,7 +428,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"hue".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
v => Err((
@ -442,7 +442,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"saturation".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
v => Err((
@ -456,7 +456,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"lightness".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
v => Err((
@ -470,7 +470,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"adjust-hue".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -500,7 +500,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"lighten".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -530,7 +530,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"darken".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -560,7 +560,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"saturate".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
if args.len() == 1 {
return Ok(Value::Ident(
format!(
@ -607,7 +607,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"desaturate".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -637,7 +637,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"grayscale".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
Value::Dimension(n, u) => {
@ -660,7 +660,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"complement".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -677,7 +677,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"invert".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let weight = match arg!(
args,
scope,

View File

@ -10,7 +10,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"alpha".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
v => Err((
@ -24,7 +24,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"opacity".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
Value::Dimension(num, unit) => Ok(Value::Ident(
@ -42,7 +42,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"opacify".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -72,7 +72,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"fade-in".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -102,7 +102,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"transparentize".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {
@ -132,7 +132,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"fade-out".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {

View File

@ -268,7 +268,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"ie-hex-str".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
v => {

View File

@ -666,7 +666,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"red".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
v => Err((
@ -680,7 +680,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"green".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
v => Err((
@ -694,7 +694,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"blue".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
v => Err((
@ -708,7 +708,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"mix".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 3);
args.max_args(3)?;
let color1 = match arg!(args, scope, super_selector, 0, "color1") {
Value::Color(c) => c,
v => {

View File

@ -12,7 +12,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"length".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let len = match arg!(args, scope, super_selector, 0, "list") {
Value::List(v, ..) => Number::from(v.len()),
Value::Map(m) => Number::from(m.len()),
@ -24,7 +24,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"nth".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let list = match arg!(args, scope, super_selector, 0, "list") {
Value::List(v, ..) => v,
Value::Map(m) => m.entries(),
@ -71,7 +71,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"list-separator".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
Ok(Value::Ident(
match arg!(args, scope, super_selector, 0, "list") {
Value::List(_, sep, ..) => sep.name(),
@ -85,7 +85,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"set-nth".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 3);
args.max_args(3)?;
let (mut list, sep, brackets) = match arg!(args, scope, super_selector, 0, "list") {
Value::List(v, sep, b) => (v, sep, b),
Value::Map(m) => (m.entries(), ListSeparator::Comma, Brackets::None),
@ -134,7 +134,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"append".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 3);
args.max_args(3)?;
let (mut list, sep, brackets) = match arg!(args, scope, super_selector, 0, "list") {
Value::List(v, sep, b) => (v, sep, b),
v => (vec![v], ListSeparator::Space, Brackets::None),
@ -179,7 +179,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"join".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 4);
args.max_args(4)?;
let (mut list1, sep1, brackets) = match arg!(args, scope, super_selector, 0, "list1") {
Value::List(v, sep, brackets) => (v, sep, brackets),
Value::Map(m) => (m.entries(), ListSeparator::Comma, Brackets::None),
@ -255,7 +255,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"is-bracketed".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
Ok(Value::bool(
match arg!(args, scope, super_selector, 0, "list") {
Value::List(.., brackets) => match brackets {
@ -270,7 +270,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"index".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let list = match arg!(args, scope, super_selector, 0, "list") {
Value::List(v, ..) => v,
Value::Map(m) => m.entries(),

View File

@ -36,25 +36,6 @@ macro_rules! named_arg {
};
}
macro_rules! max_args {
($args:ident, $count:literal) => {
if $args.len() > $count {
let mut err = String::with_capacity(50);
err.push_str(&format!("Only {} argument", $count));
if $count != 1 {
err.push('s');
}
err.push_str(&format!(" allowed, but {} ", $args.len()));
if $args.len() == 1 {
err.push_str("was passed.")
} else {
err.push_str("were passed.")
}
return Err((err, $args.span()).into());
}
};
}
macro_rules! bound {
($args:ident, $name:literal, $arg:ident, $unit:ident, $low:literal, $high:literal) => {
if $arg > Number::from($high) || $arg < Number::from($low) {

View File

@ -8,7 +8,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"map-get".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let key = arg!(args, scope, super_selector, 1, "key");
let map = match arg!(args, scope, super_selector, 0, "map") {
Value::Map(m) => m,
@ -27,7 +27,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"map-has-key".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let key = arg!(args, scope, super_selector, 1, "key");
let map = match arg!(args, scope, super_selector, 0, "map") {
Value::Map(m) => m,
@ -46,7 +46,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"map-keys".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let map = match arg!(args, scope, super_selector, 0, "map") {
Value::Map(m) => m,
Value::List(v, ..) if v.is_empty() => SassMap::new(),
@ -68,7 +68,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"map-values".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let map = match arg!(args, scope, super_selector, 0, "map") {
Value::Map(m) => m,
Value::List(v, ..) if v.is_empty() => SassMap::new(),
@ -90,7 +90,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"map-merge".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let mut map1 = match arg!(args, scope, super_selector, 0, "map1") {
Value::Map(m) => m,
Value::List(v, ..) if v.is_empty() => SassMap::new(),

View File

@ -13,7 +13,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"percentage".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let num = match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(n, Unit::None) => n * Number::from(100),
v @ Value::Dimension(..) => {
@ -43,7 +43,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"round".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(n, u) => Ok(Value::Dimension(n.round(), u)),
v => Err((
@ -60,7 +60,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"ceil".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(n, u) => Ok(Value::Dimension(n.ceil(), u)),
v => Err((
@ -77,7 +77,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"floor".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(n, u) => Ok(Value::Dimension(n.floor(), u)),
v => Err((
@ -94,7 +94,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"abs".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(n, u) => Ok(Value::Dimension(n.abs(), u)),
v => Err((
@ -111,7 +111,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"comparable".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let unit1 = match arg!(args, scope, super_selector, 0, "number1") {
Value::Dimension(_, u) => u,
v => {
@ -147,7 +147,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"random".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let limit = match arg!(args, scope, super_selector, 0, "limit" = Value::Null) {
Value::Dimension(n, _) => n,
Value::Null => {

View File

@ -12,7 +12,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"if".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 3);
args.max_args(3)?;
if arg!(args, scope, super_selector, 0, "condition").is_true(args.span())? {
Ok(arg!(args, scope, super_selector, 1, "if-true"))
} else {
@ -23,7 +23,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"feature-exists".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "feature") {
Value::Ident(s, _) => match s.as_str() {
// A local variable will shadow a global variable unless
@ -57,7 +57,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"unit".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let unit = match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(_, u) => u.to_string(),
v => {
@ -77,7 +77,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"type-of".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
let value = arg!(args, scope, super_selector, 0, "value");
Ok(Value::Ident(
value.kind(args.span())?.to_owned(),
@ -88,7 +88,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"unitless".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(_, Unit::None) => Ok(Value::True),
Value::Dimension(_, _) => Ok(Value::False),
@ -99,7 +99,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"inspect".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
Ok(Value::Ident(
arg!(args, scope, super_selector, 0, "value").inspect(args.span())?,
QuoteKind::None,
@ -109,7 +109,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"variable-exists".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(scope.var_exists(&s))),
v => Err((
@ -123,7 +123,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"global-variable-exists".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))),
v => Err((
@ -137,7 +137,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"mixin-exists".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(scope.mixin_exists(&s))),
v => Err((
@ -151,7 +151,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"function-exists".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(
scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(&s),
@ -167,7 +167,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"get-function".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 3);
args.max_args(3)?;
let name = match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => s,
v => {

View File

@ -15,7 +15,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"to-upper-case".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_uppercase(), q)),
v => Err((
@ -32,7 +32,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"to-lower-case".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, q) => Ok(Value::Ident(i.to_ascii_lowercase(), q)),
v => Err((
@ -49,7 +49,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"str-length".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, _) => Ok(Value::Dimension(
Number::from(i.chars().count()),
@ -69,7 +69,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"quote".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, _) => Ok(Value::Ident(i, QuoteKind::Quoted)),
v => Err((
@ -86,7 +86,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"unquote".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1);
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
i @ Value::Ident(..) => Ok(i.unquote()),
v => Err((
@ -103,7 +103,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"str-slice".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 3);
args.max_args(3)?;
let (string, quotes) = match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(s, q) => (s, q),
v => {
@ -207,7 +207,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"str-index".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 2);
args.max_args(2)?;
let s1 = match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, _) => i,
v => {
@ -245,7 +245,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"str-insert".to_owned(),
Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 3);
args.max_args(3)?;
let (s1, quotes) = match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, q) => (i, q),
v => {
@ -349,7 +349,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
f.insert(
"unique-id".to_owned(),
Builtin::new(|args, _, _| {
max_args!(args, 0);
args.max_args(0)?;
let mut rng = thread_rng();
let string = std::iter::repeat(())
.map(|()| rng.sample(Alphanumeric))