From ef282c5c1833611c622af7d18d6e6a1b4e665b29 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 6 Apr 2020 00:27:09 -0400 Subject: [PATCH] consolidate inspect implementations --- src/atrule/mod.rs | 12 +----------- src/builtin/meta.rs | 11 ++--------- src/value/mod.rs | 11 +++++++++++ 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/atrule/mod.rs b/src/atrule/mod.rs index 5a0ff54..6323469 100644 --- a/src/atrule/mod.rs +++ b/src/atrule/mod.rs @@ -83,17 +83,7 @@ impl AtRule { toks.next(); } devour_whitespace(toks); - AtRule::Debug( - pos, - match message { - Value::List(v, _, brackets) if v.is_empty() => match brackets { - Brackets::None => "()".to_string(), - Brackets::Bracketed => "[]".to_string(), - }, - Value::Function(f) => format!("get-function(\"{}\")", f.name()), - v => v.to_string(), - }, - ) + AtRule::Debug(pos, message.inspect()) } AtRuleKind::Mixin => { let (name, mixin) = Mixin::decl_from_tokens(toks, scope, super_selector)?; diff --git a/src/builtin/meta.rs b/src/builtin/meta.rs index a3711d4..cc7557f 100644 --- a/src/builtin/meta.rs +++ b/src/builtin/meta.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use super::{Builtin, GLOBAL_FUNCTIONS}; -use crate::common::{Brackets, QuoteKind}; +use crate::common::QuoteKind; use crate::scope::global_var_exists; use crate::unit::Unit; use crate::value::{SassFunction, Value}; @@ -80,14 +80,7 @@ pub(crate) fn register(f: &mut HashMap) { Builtin::new(|mut args, scope, super_selector| { max_args!(args, 1); Ok(Value::Ident( - match arg!(args, scope, super_selector, 0, "value") { - Value::List(v, _, brackets) if v.is_empty() => match brackets { - Brackets::None => "()".to_string(), - Brackets::Bracketed => "[]".to_string(), - }, - Value::Function(f) => format!("get-function(\"{}\")", f.name()), - v => v.to_string(), - }, + arg!(args, scope, super_selector, 0, "value").inspect(), QuoteKind::None, )) }), diff --git a/src/value/mod.rs b/src/value/mod.rs index 5a0a330..009fe52 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -186,6 +186,17 @@ impl Value { } } + pub fn inspect(&self) -> String { + match self { + Value::List(v, _, brackets) if v.is_empty() => match brackets { + Brackets::None => "()".to_string(), + Brackets::Bracketed => "[]".to_string(), + }, + Value::Function(f) => format!("get-function(\"{}\")", f.name()), + v => v.to_string(), + } + } + pub fn equals(self, other: Value) -> SassResult { Ok(match self.eval()? { Self::Ident(s1, ..) => match other {