diff --git a/src/args.rs b/src/args.rs index c08c8f1..2a0e98e 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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>( diff --git a/src/builtin/color/hsl.rs b/src/builtin/color/hsl.rs index 0759fbc..218cdf5 100644 --- a/src/builtin/color/hsl.rs +++ b/src/builtin/color/hsl.rs @@ -428,7 +428,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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, diff --git a/src/builtin/color/opacity.rs b/src/builtin/color/opacity.rs index 6029ebb..f1f88c9 100644 --- a/src/builtin/color/opacity.rs +++ b/src/builtin/color/opacity.rs @@ -10,7 +10,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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) { 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) { 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 => { diff --git a/src/builtin/color/other.rs b/src/builtin/color/other.rs index 0aa73fa..d194d77 100644 --- a/src/builtin/color/other.rs +++ b/src/builtin/color/other.rs @@ -268,7 +268,7 @@ pub(crate) fn register(f: &mut HashMap) { 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 => { diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index 097386c..5025c78 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -666,7 +666,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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 => { diff --git a/src/builtin/list.rs b/src/builtin/list.rs index 85ec2ce..a96b366 100644 --- a/src/builtin/list.rs +++ b/src/builtin/list.rs @@ -12,7 +12,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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(), diff --git a/src/builtin/macros.rs b/src/builtin/macros.rs index 4fad323..b0bca29 100644 --- a/src/builtin/macros.rs +++ b/src/builtin/macros.rs @@ -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) { diff --git a/src/builtin/map.rs b/src/builtin/map.rs index 9052397..38d6a4a 100644 --- a/src/builtin/map.rs +++ b/src/builtin/map.rs @@ -8,7 +8,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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) { 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(), diff --git a/src/builtin/math.rs b/src/builtin/math.rs index a220f41..afaf45d 100644 --- a/src/builtin/math.rs +++ b/src/builtin/math.rs @@ -13,7 +13,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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) { 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) { 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) { 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 => { diff --git a/src/builtin/meta.rs b/src/builtin/meta.rs index f2eaf5c..352b768 100644 --- a/src/builtin/meta.rs +++ b/src/builtin/meta.rs @@ -12,7 +12,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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 => { diff --git a/src/builtin/string.rs b/src/builtin/string.rs index 95fda11..59bf248 100644 --- a/src/builtin/string.rs +++ b/src/builtin/string.rs @@ -15,7 +15,7 @@ pub(crate) fn register(f: &mut HashMap) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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))