replace max_args! macro with builtin method
This commit is contained in:
parent
4d989b60b1
commit
680790c49a
21
src/args.rs
21
src/args.rs
@ -170,6 +170,27 @@ impl CallArgs {
|
|||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.0.is_empty()
|
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>>(
|
pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
|
||||||
|
@ -428,7 +428,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"hue".to_owned(),
|
"hue".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
|
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -442,7 +442,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"saturation".to_owned(),
|
"saturation".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
|
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -456,7 +456,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"lightness".to_owned(),
|
"lightness".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
|
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -470,7 +470,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"adjust-hue".to_owned(),
|
"adjust-hue".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -500,7 +500,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"lighten".to_owned(),
|
"lighten".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -530,7 +530,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"darken".to_owned(),
|
"darken".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -560,7 +560,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"saturate".to_owned(),
|
"saturate".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 2);
|
args.max_args(2)?;
|
||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
return Ok(Value::Ident(
|
return Ok(Value::Ident(
|
||||||
format!(
|
format!(
|
||||||
@ -607,7 +607,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"desaturate".to_owned(),
|
"desaturate".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -637,7 +637,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"grayscale".to_owned(),
|
"grayscale".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
Value::Dimension(n, u) => {
|
Value::Dimension(n, u) => {
|
||||||
@ -660,7 +660,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"complement".to_owned(),
|
"complement".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -677,7 +677,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"invert".to_owned(),
|
"invert".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 2);
|
args.max_args(2)?;
|
||||||
let weight = match arg!(
|
let weight = match arg!(
|
||||||
args,
|
args,
|
||||||
scope,
|
scope,
|
||||||
|
@ -10,7 +10,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"alpha".to_owned(),
|
"alpha".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -24,7 +24,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"opacity".to_owned(),
|
"opacity".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
Value::Dimension(num, unit) => Ok(Value::Ident(
|
Value::Dimension(num, unit) => Ok(Value::Ident(
|
||||||
@ -42,7 +42,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"opacify".to_owned(),
|
"opacify".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -72,7 +72,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"fade-in".to_owned(),
|
"fade-in".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -102,7 +102,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"transparentize".to_owned(),
|
"transparentize".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
@ -132,7 +132,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"fade-out".to_owned(),
|
"fade-out".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
|
@ -268,7 +268,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"ie-hex-str".to_owned(),
|
"ie-hex-str".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color = match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
|
@ -666,7 +666,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"red".to_owned(),
|
"red".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -680,7 +680,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"green".to_owned(),
|
"green".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -694,7 +694,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"blue".to_owned(),
|
"blue".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "color") {
|
match arg!(args, scope, super_selector, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -708,7 +708,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"mix".to_owned(),
|
"mix".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let color1 = match arg!(args, scope, super_selector, 0, "color1") {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => {
|
v => {
|
||||||
|
@ -12,7 +12,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"length".to_owned(),
|
"length".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let len = match arg!(args, scope, super_selector, 0, "list") {
|
||||||
Value::List(v, ..) => Number::from(v.len()),
|
Value::List(v, ..) => Number::from(v.len()),
|
||||||
Value::Map(m) => Number::from(m.len()),
|
Value::Map(m) => Number::from(m.len()),
|
||||||
@ -24,7 +24,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"nth".to_owned(),
|
"nth".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let list = match arg!(args, scope, super_selector, 0, "list") {
|
||||||
Value::List(v, ..) => v,
|
Value::List(v, ..) => v,
|
||||||
Value::Map(m) => m.entries(),
|
Value::Map(m) => m.entries(),
|
||||||
@ -71,7 +71,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"list-separator".to_owned(),
|
"list-separator".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
Ok(Value::Ident(
|
Ok(Value::Ident(
|
||||||
match arg!(args, scope, super_selector, 0, "list") {
|
match arg!(args, scope, super_selector, 0, "list") {
|
||||||
Value::List(_, sep, ..) => sep.name(),
|
Value::List(_, sep, ..) => sep.name(),
|
||||||
@ -85,7 +85,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"set-nth".to_owned(),
|
"set-nth".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let (mut list, sep, brackets) = match arg!(args, scope, super_selector, 0, "list") {
|
||||||
Value::List(v, sep, b) => (v, sep, b),
|
Value::List(v, sep, b) => (v, sep, b),
|
||||||
Value::Map(m) => (m.entries(), ListSeparator::Comma, Brackets::None),
|
Value::Map(m) => (m.entries(), ListSeparator::Comma, Brackets::None),
|
||||||
@ -134,7 +134,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"append".to_owned(),
|
"append".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let (mut list, sep, brackets) = match arg!(args, scope, super_selector, 0, "list") {
|
||||||
Value::List(v, sep, b) => (v, sep, b),
|
Value::List(v, sep, b) => (v, sep, b),
|
||||||
v => (vec![v], ListSeparator::Space, Brackets::None),
|
v => (vec![v], ListSeparator::Space, Brackets::None),
|
||||||
@ -179,7 +179,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"join".to_owned(),
|
"join".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let (mut list1, sep1, brackets) = match arg!(args, scope, super_selector, 0, "list1") {
|
||||||
Value::List(v, sep, brackets) => (v, sep, brackets),
|
Value::List(v, sep, brackets) => (v, sep, brackets),
|
||||||
Value::Map(m) => (m.entries(), ListSeparator::Comma, Brackets::None),
|
Value::Map(m) => (m.entries(), ListSeparator::Comma, Brackets::None),
|
||||||
@ -255,7 +255,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"is-bracketed".to_owned(),
|
"is-bracketed".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
Ok(Value::bool(
|
Ok(Value::bool(
|
||||||
match arg!(args, scope, super_selector, 0, "list") {
|
match arg!(args, scope, super_selector, 0, "list") {
|
||||||
Value::List(.., brackets) => match brackets {
|
Value::List(.., brackets) => match brackets {
|
||||||
@ -270,7 +270,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"index".to_owned(),
|
"index".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let list = match arg!(args, scope, super_selector, 0, "list") {
|
||||||
Value::List(v, ..) => v,
|
Value::List(v, ..) => v,
|
||||||
Value::Map(m) => m.entries(),
|
Value::Map(m) => m.entries(),
|
||||||
|
@ -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 {
|
macro_rules! bound {
|
||||||
($args:ident, $name:literal, $arg:ident, $unit:ident, $low:literal, $high:literal) => {
|
($args:ident, $name:literal, $arg:ident, $unit:ident, $low:literal, $high:literal) => {
|
||||||
if $arg > Number::from($high) || $arg < Number::from($low) {
|
if $arg > Number::from($high) || $arg < Number::from($low) {
|
||||||
|
@ -8,7 +8,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"map-get".to_owned(),
|
"map-get".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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 key = arg!(args, scope, super_selector, 1, "key");
|
||||||
let map = match arg!(args, scope, super_selector, 0, "map") {
|
let map = match arg!(args, scope, super_selector, 0, "map") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
@ -27,7 +27,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"map-has-key".to_owned(),
|
"map-has-key".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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 key = arg!(args, scope, super_selector, 1, "key");
|
||||||
let map = match arg!(args, scope, super_selector, 0, "map") {
|
let map = match arg!(args, scope, super_selector, 0, "map") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
@ -46,7 +46,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"map-keys".to_owned(),
|
"map-keys".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let map = match arg!(args, scope, super_selector, 0, "map") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
||||||
@ -68,7 +68,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"map-values".to_owned(),
|
"map-values".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let map = match arg!(args, scope, super_selector, 0, "map") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
||||||
@ -90,7 +90,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"map-merge".to_owned(),
|
"map-merge".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let mut map1 = match arg!(args, scope, super_selector, 0, "map1") {
|
||||||
Value::Map(m) => m,
|
Value::Map(m) => m,
|
||||||
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
||||||
|
@ -13,7 +13,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"percentage".to_owned(),
|
"percentage".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let num = match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(n, Unit::None) => n * Number::from(100),
|
Value::Dimension(n, Unit::None) => n * Number::from(100),
|
||||||
v @ Value::Dimension(..) => {
|
v @ Value::Dimension(..) => {
|
||||||
@ -43,7 +43,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"round".to_owned(),
|
"round".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.round(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.round(), u)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -60,7 +60,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"ceil".to_owned(),
|
"ceil".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.ceil(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.ceil(), u)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -77,7 +77,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"floor".to_owned(),
|
"floor".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.floor(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.floor(), u)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -94,7 +94,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"abs".to_owned(),
|
"abs".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(n, u) => Ok(Value::Dimension(n.abs(), u)),
|
Value::Dimension(n, u) => Ok(Value::Dimension(n.abs(), u)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -111,7 +111,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"comparable".to_owned(),
|
"comparable".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let unit1 = match arg!(args, scope, super_selector, 0, "number1") {
|
||||||
Value::Dimension(_, u) => u,
|
Value::Dimension(_, u) => u,
|
||||||
v => {
|
v => {
|
||||||
@ -147,7 +147,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"random".to_owned(),
|
"random".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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) {
|
let limit = match arg!(args, scope, super_selector, 0, "limit" = Value::Null) {
|
||||||
Value::Dimension(n, _) => n,
|
Value::Dimension(n, _) => n,
|
||||||
Value::Null => {
|
Value::Null => {
|
||||||
|
@ -12,7 +12,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"if".to_owned(),
|
"if".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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())? {
|
if arg!(args, scope, super_selector, 0, "condition").is_true(args.span())? {
|
||||||
Ok(arg!(args, scope, super_selector, 1, "if-true"))
|
Ok(arg!(args, scope, super_selector, 1, "if-true"))
|
||||||
} else {
|
} else {
|
||||||
@ -23,7 +23,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"feature-exists".to_owned(),
|
"feature-exists".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "feature") {
|
match arg!(args, scope, super_selector, 0, "feature") {
|
||||||
Value::Ident(s, _) => match s.as_str() {
|
Value::Ident(s, _) => match s.as_str() {
|
||||||
// A local variable will shadow a global variable unless
|
// A local variable will shadow a global variable unless
|
||||||
@ -57,7 +57,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"unit".to_owned(),
|
"unit".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let unit = match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(_, u) => u.to_string(),
|
Value::Dimension(_, u) => u.to_string(),
|
||||||
v => {
|
v => {
|
||||||
@ -77,7 +77,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"type-of".to_owned(),
|
"type-of".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
let value = arg!(args, scope, super_selector, 0, "value");
|
let value = arg!(args, scope, super_selector, 0, "value");
|
||||||
Ok(Value::Ident(
|
Ok(Value::Ident(
|
||||||
value.kind(args.span())?.to_owned(),
|
value.kind(args.span())?.to_owned(),
|
||||||
@ -88,7 +88,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"unitless".to_owned(),
|
"unitless".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "number") {
|
match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(_, Unit::None) => Ok(Value::True),
|
Value::Dimension(_, Unit::None) => Ok(Value::True),
|
||||||
Value::Dimension(_, _) => Ok(Value::False),
|
Value::Dimension(_, _) => Ok(Value::False),
|
||||||
@ -99,7 +99,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"inspect".to_owned(),
|
"inspect".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
Ok(Value::Ident(
|
Ok(Value::Ident(
|
||||||
arg!(args, scope, super_selector, 0, "value").inspect(args.span())?,
|
arg!(args, scope, super_selector, 0, "value").inspect(args.span())?,
|
||||||
QuoteKind::None,
|
QuoteKind::None,
|
||||||
@ -109,7 +109,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"variable-exists".to_owned(),
|
"variable-exists".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "name") {
|
match arg!(args, scope, super_selector, 0, "name") {
|
||||||
Value::Ident(s, _) => Ok(Value::bool(scope.var_exists(&s))),
|
Value::Ident(s, _) => Ok(Value::bool(scope.var_exists(&s))),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -123,7 +123,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"global-variable-exists".to_owned(),
|
"global-variable-exists".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "name") {
|
match arg!(args, scope, super_selector, 0, "name") {
|
||||||
Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))),
|
Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -137,7 +137,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"mixin-exists".to_owned(),
|
"mixin-exists".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(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(scope.mixin_exists(&s))),
|
Value::Ident(s, _) => Ok(Value::bool(scope.mixin_exists(&s))),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -151,7 +151,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"function-exists".to_owned(),
|
"function-exists".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(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),
|
||||||
@ -167,7 +167,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"get-function".to_owned(),
|
"get-function".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let name = match arg!(args, scope, super_selector, 0, "name") {
|
||||||
Value::Ident(s, _) => s,
|
Value::Ident(s, _) => s,
|
||||||
v => {
|
v => {
|
||||||
|
@ -15,7 +15,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"to-upper-case".to_owned(),
|
"to-upper-case".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 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)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -32,7 +32,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"to-lower-case".to_owned(),
|
"to-lower-case".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 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)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -49,7 +49,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"str-length".to_owned(),
|
"str-length".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
Value::Ident(i, _) => Ok(Value::Dimension(
|
Value::Ident(i, _) => Ok(Value::Dimension(
|
||||||
Number::from(i.chars().count()),
|
Number::from(i.chars().count()),
|
||||||
@ -69,7 +69,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"quote".to_owned(),
|
"quote".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
Value::Ident(i, _) => Ok(Value::Ident(i, QuoteKind::Quoted)),
|
Value::Ident(i, _) => Ok(Value::Ident(i, QuoteKind::Quoted)),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -86,7 +86,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"unquote".to_owned(),
|
"unquote".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
Builtin::new(|mut args, scope, super_selector| {
|
||||||
max_args!(args, 1);
|
args.max_args(1)?;
|
||||||
match arg!(args, scope, super_selector, 0, "string") {
|
match arg!(args, scope, super_selector, 0, "string") {
|
||||||
i @ Value::Ident(..) => Ok(i.unquote()),
|
i @ Value::Ident(..) => Ok(i.unquote()),
|
||||||
v => Err((
|
v => Err((
|
||||||
@ -103,7 +103,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"str-slice".to_owned(),
|
"str-slice".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let (string, quotes) = match arg!(args, scope, super_selector, 0, "string") {
|
||||||
Value::Ident(s, q) => (s, q),
|
Value::Ident(s, q) => (s, q),
|
||||||
v => {
|
v => {
|
||||||
@ -207,7 +207,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"str-index".to_owned(),
|
"str-index".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let s1 = match arg!(args, scope, super_selector, 0, "string") {
|
||||||
Value::Ident(i, _) => i,
|
Value::Ident(i, _) => i,
|
||||||
v => {
|
v => {
|
||||||
@ -245,7 +245,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"str-insert".to_owned(),
|
"str-insert".to_owned(),
|
||||||
Builtin::new(|mut args, scope, super_selector| {
|
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") {
|
let (s1, quotes) = match arg!(args, scope, super_selector, 0, "string") {
|
||||||
Value::Ident(i, q) => (i, q),
|
Value::Ident(i, q) => (i, q),
|
||||||
v => {
|
v => {
|
||||||
@ -349,7 +349,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"unique-id".to_owned(),
|
"unique-id".to_owned(),
|
||||||
Builtin::new(|args, _, _| {
|
Builtin::new(|args, _, _| {
|
||||||
max_args!(args, 0);
|
args.max_args(0)?;
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
let string = std::iter::repeat(())
|
let string = std::iter::repeat(())
|
||||||
.map(|()| rng.sample(Alphanumeric))
|
.map(|()| rng.sample(Alphanumeric))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user