consolidate inspect implementations

This commit is contained in:
ConnorSkees 2020-04-06 00:27:09 -04:00
parent 4ab4f401d5
commit ef282c5c18
3 changed files with 14 additions and 20 deletions

View File

@ -83,17 +83,7 @@ impl AtRule {
toks.next(); toks.next();
} }
devour_whitespace(toks); devour_whitespace(toks);
AtRule::Debug( AtRule::Debug(pos, message.inspect())
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(),
},
)
} }
AtRuleKind::Mixin => { AtRuleKind::Mixin => {
let (name, mixin) = Mixin::decl_from_tokens(toks, scope, super_selector)?; let (name, mixin) = Mixin::decl_from_tokens(toks, scope, super_selector)?;

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use super::{Builtin, GLOBAL_FUNCTIONS}; use super::{Builtin, GLOBAL_FUNCTIONS};
use crate::common::{Brackets, QuoteKind}; use crate::common::QuoteKind;
use crate::scope::global_var_exists; use crate::scope::global_var_exists;
use crate::unit::Unit; use crate::unit::Unit;
use crate::value::{SassFunction, Value}; use crate::value::{SassFunction, Value};
@ -80,14 +80,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
Builtin::new(|mut args, scope, super_selector| { Builtin::new(|mut args, scope, super_selector| {
max_args!(args, 1); max_args!(args, 1);
Ok(Value::Ident( Ok(Value::Ident(
match arg!(args, scope, super_selector, 0, "value") { arg!(args, scope, super_selector, 0, "value").inspect(),
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(),
},
QuoteKind::None, QuoteKind::None,
)) ))
}), }),

View File

@ -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<bool> { pub fn equals(self, other: Value) -> SassResult<bool> {
Ok(match self.eval()? { Ok(match self.eval()? {
Self::Ident(s1, ..) => match other { Self::Ident(s1, ..) => match other {