rename Value::Ident to Value::String

This commit is contained in:
ConnorSkees 2020-05-22 14:35:41 -04:00
parent 969726eb30
commit 283a2097ff
14 changed files with 135 additions and 143 deletions

View File

@ -107,7 +107,7 @@ fn inner_hsl(
); );
} }
string.push(')'); string.push(')');
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
v => { v => {
return Err(( return Err((
@ -136,7 +136,7 @@ fn inner_hsl(
); );
} }
string.push(')'); string.push(')');
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
v => { v => {
return Err(( return Err((
@ -167,7 +167,7 @@ fn inner_hsl(
); );
} }
string.push(')'); string.push(')');
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
v => { v => {
return Err(( return Err((
@ -200,7 +200,7 @@ fn inner_hsl(
.into()) .into())
} }
v if v.is_special_function() => { v if v.is_special_function() => {
return Ok(Value::Ident( return Ok(Value::String(
format!( format!(
"{}({}, {}, {}, {})", "{}({}, {}, {}, {})",
name, name,
@ -357,7 +357,7 @@ fn darken(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassR
fn saturate(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn saturate(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(2)?; args.max_args(2)?;
if args.len() == 1 { if args.len() == 1 {
return Ok(Value::Ident( return Ok(Value::String(
format!( format!(
"saturate({})", "saturate({})",
arg!(args, scope, super_selector, 0, "amount").to_css_string(args.span())? arg!(args, scope, super_selector, 0, "amount").to_css_string(args.span())?
@ -382,7 +382,7 @@ fn saturate(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sas
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) => {
return Ok(Value::Ident( return Ok(Value::String(
format!("saturate({}{})", n, u), format!("saturate({}{})", n, u),
QuoteKind::None, QuoteKind::None,
)) ))
@ -431,7 +431,7 @@ fn grayscale(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
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) => {
return Ok(Value::Ident( return Ok(Value::String(
format!("grayscale({}{})", n, u), format!("grayscale({}{})", n, u),
QuoteKind::None, QuoteKind::None,
)) ))
@ -486,7 +486,7 @@ fn invert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassR
match arg!(args, scope, super_selector, 0, "color") { match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Color(Box::new(c.invert(weight)))), Value::Color(c) => Ok(Value::Color(Box::new(c.invert(weight)))),
Value::Dimension(n, Unit::Percent) => { Value::Dimension(n, Unit::Percent) => {
Ok(Value::Ident(format!("invert({}%)", n), QuoteKind::None)) Ok(Value::String(format!("invert({}%)", n), QuoteKind::None))
} }
Value::Dimension(..) => Err(( Value::Dimension(..) => Err((
"Only one argument may be passed to the plain-CSS invert() function.", "Only one argument may be passed to the plain-CSS invert() function.",

View File

@ -25,7 +25,7 @@ fn opacity(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sass
args.max_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::String(
format!("opacity({}{})", num, unit), format!("opacity({}{})", num, unit),
QuoteKind::None, QuoteKind::None,
)), )),

View File

@ -345,7 +345,7 @@ fn ie_hex_str(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
.into()) .into())
} }
}; };
Ok(Value::Ident(color.to_ie_hex_str(), QuoteKind::None)) Ok(Value::String(color.to_ie_hex_str(), QuoteKind::None))
} }
pub(crate) fn declare(f: &mut GlobalFunctionMap) { pub(crate) fn declare(f: &mut GlobalFunctionMap) {

View File

@ -45,7 +45,7 @@ fn inner_rgb(
Some(v) if v.is_special_function() => { Some(v) if v.is_special_function() => {
let green = channels.pop().unwrap(); let green = channels.pop().unwrap();
let red = channels.pop().unwrap(); let red = channels.pop().unwrap();
return Ok(Value::Ident( return Ok(Value::String(
format!( format!(
"{}({}, {}, {})", "{}({}, {}, {})",
name, name,
@ -80,7 +80,7 @@ fn inner_rgb(
), ),
None => format!("{}({} {})", name, v.to_css_string(args.span())?, blue), None => format!("{}({} {})", name, v.to_css_string(args.span())?, blue),
}; };
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
Some(v) => { Some(v) => {
return Err(( return Err((
@ -96,7 +96,7 @@ fn inner_rgb(
Some(Value::Dimension(n, Unit::None)) => n, Some(Value::Dimension(n, Unit::None)) => n,
Some(Value::Dimension(n, Unit::Percent)) => (n / Number::from(100)) * Number::from(255), Some(Value::Dimension(n, Unit::Percent)) => (n / Number::from(100)) * Number::from(255),
Some(v) if v.is_special_function() => { Some(v) if v.is_special_function() => {
return Ok(Value::Ident( return Ok(Value::String(
format!( format!(
"{}({}, {}, {})", "{}({}, {}, {})",
name, name,
@ -125,7 +125,7 @@ fn inner_rgb(
Value::Color(c) => c, Value::Color(c) => c,
v if v.is_special_function() => { v if v.is_special_function() => {
let alpha = arg!(args, scope, super_selector, 1, "alpha"); let alpha = arg!(args, scope, super_selector, 1, "alpha");
return Ok(Value::Ident( return Ok(Value::String(
format!( format!(
"{}({}, {})", "{}({}, {})",
name, name,
@ -157,7 +157,7 @@ fn inner_rgb(
.into()) .into())
} }
v if v.is_special_function() => { v if v.is_special_function() => {
return Ok(Value::Ident( return Ok(Value::String(
format!( format!(
"{}({}, {}, {}, {})", "{}({}, {}, {}, {})",
name, name,
@ -210,7 +210,7 @@ fn inner_rgb(
); );
} }
string.push(')'); string.push(')');
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
v => { v => {
return Err(( return Err((
@ -250,7 +250,7 @@ fn inner_rgb(
); );
} }
string.push(')'); string.push(')');
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
v => { v => {
return Err(( return Err((
@ -289,7 +289,7 @@ fn inner_rgb(
); );
} }
string.push(')'); string.push(')');
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
v => { v => {
return Err(( return Err((
@ -327,7 +327,7 @@ fn inner_rgb(
blue, blue,
v.to_css_string(args.span())? v.to_css_string(args.span())?
); );
return Ok(Value::Ident(string, QuoteKind::None)); return Ok(Value::String(string, QuoteKind::None));
} }
v => { v => {
return Err(( return Err((

View File

@ -71,7 +71,7 @@ fn list_separator(
super_selector: &Selector, super_selector: &Selector,
) -> SassResult<Value> { ) -> SassResult<Value> {
args.max_args(1)?; args.max_args(1)?;
Ok(Value::Ident( Ok(Value::String(
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(),
_ => ListSeparator::Space.name(), _ => ListSeparator::Space.name(),
@ -140,9 +140,9 @@ fn append(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassR
scope, scope,
super_selector, super_selector,
2, 2,
"separator" = Value::Ident("auto".to_owned(), QuoteKind::None) "separator" = Value::String("auto".to_owned(), QuoteKind::None)
) { ) {
Value::Ident(s, ..) => match s.as_str() { Value::String(s, ..) => match s.as_str() {
"auto" => sep, "auto" => sep,
"comma" => ListSeparator::Comma, "comma" => ListSeparator::Comma,
"space" => ListSeparator::Space, "space" => ListSeparator::Space,
@ -188,9 +188,9 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
scope, scope,
super_selector, super_selector,
2, 2,
"separator" = Value::Ident("auto".to_owned(), QuoteKind::None) "separator" = Value::String("auto".to_owned(), QuoteKind::None)
) { ) {
Value::Ident(s, ..) => match s.as_str() { Value::String(s, ..) => match s.as_str() {
"auto" => { "auto" => {
if list1.is_empty() || (list1.len() == 1 && sep1 == ListSeparator::Space) { if list1.is_empty() || (list1.len() == 1 && sep1 == ListSeparator::Space) {
sep2 sep2
@ -225,9 +225,9 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
scope, scope,
super_selector, super_selector,
3, 3,
"bracketed" = Value::Ident("auto".to_owned(), QuoteKind::None) "bracketed" = Value::String("auto".to_owned(), QuoteKind::None)
) { ) {
Value::Ident(s, ..) => match s.as_str() { Value::String(s, ..) => match s.as_str() {
"auto" => brackets, "auto" => brackets,
_ => Brackets::Bracketed, _ => Brackets::Bracketed,
}, },

View File

@ -27,7 +27,7 @@ fn feature_exists(
) -> SassResult<Value> { ) -> SassResult<Value> {
args.max_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, _) => Ok(match s.as_str() { Value::String(s, _) => Ok(match s.as_str() {
// A local variable will shadow a global variable unless // A local variable will shadow a global variable unless
// `!global` is used. // `!global` is used.
"global-variable-shadowing" => Value::True, "global-variable-shadowing" => Value::True,
@ -71,13 +71,13 @@ fn unit(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
.into()) .into())
} }
}; };
Ok(Value::Ident(unit, QuoteKind::Quoted)) Ok(Value::String(unit, QuoteKind::Quoted))
} }
fn type_of(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn type_of(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(
value.kind(args.span())?.to_owned(), value.kind(args.span())?.to_owned(),
QuoteKind::None, QuoteKind::None,
)) ))
@ -94,7 +94,7 @@ fn unitless(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sas
fn inspect(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn inspect(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?; args.max_args(1)?;
Ok(Value::Ident( Ok(Value::String(
arg!(args, scope, super_selector, 0, "value") arg!(args, scope, super_selector, 0, "value")
.inspect(args.span())? .inspect(args.span())?
.into(), .into(),
@ -109,7 +109,7 @@ fn variable_exists(
) -> SassResult<Value> { ) -> SassResult<Value> {
args.max_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::String(s, _) => Ok(Value::bool(scope.var_exists(&s))),
v => Err(( v => Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?), format!("$name: {} is not a string.", v.to_css_string(args.span())?),
args.span(), args.span(),
@ -125,7 +125,7 @@ fn global_variable_exists(
) -> SassResult<Value> { ) -> SassResult<Value> {
args.max_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::String(s, _) => Ok(Value::bool(global_var_exists(&s))),
v => Err(( v => Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?), format!("$name: {} is not a string.", v.to_css_string(args.span())?),
args.span(), args.span(),
@ -137,7 +137,7 @@ fn global_variable_exists(
fn mixin_exists(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn mixin_exists(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(s, _) => Ok(Value::bool(scope.mixin_exists(&s))),
v => Err(( v => Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?), format!("$name: {} is not a string.", v.to_css_string(args.span())?),
args.span(), args.span(),
@ -153,7 +153,7 @@ fn function_exists(
) -> SassResult<Value> { ) -> SassResult<Value> {
args.max_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::String(s, _) => Ok(Value::bool(
scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(s.as_str()), scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(s.as_str()),
)), )),
v => Err(( v => Err((
@ -167,7 +167,7 @@ fn function_exists(
fn get_function(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn get_function(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(s, _) => s,
v => { v => {
return Err(( return Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?), format!("$name: {} is not a string.", v.to_css_string(args.span())?),
@ -178,7 +178,7 @@ fn get_function(mut args: CallArgs, scope: &Scope, super_selector: &Selector) ->
}; };
let css = arg!(args, scope, super_selector, 1, "css" = Value::False).is_true(args.span())?; let css = arg!(args, scope, super_selector, 1, "css" = Value::False).is_true(args.span())?;
let module = match arg!(args, scope, super_selector, 2, "module" = Value::Null) { let module = match arg!(args, scope, super_selector, 2, "module" = Value::Null) {
Value::Ident(s, ..) => Some(s), Value::String(s, ..) => Some(s),
Value::Null => None, Value::Null => None,
v => { v => {
return Err(( return Err((

View File

@ -21,9 +21,9 @@ fn to_upper_case(
) -> SassResult<Value> { ) -> SassResult<Value> {
args.max_args(1)?; args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") { match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(mut i, q) => { Value::String(mut i, q) => {
i.make_ascii_uppercase(); i.make_ascii_uppercase();
Ok(Value::Ident(i, q)) Ok(Value::String(i, q))
} }
v => Err(( v => Err((
format!( format!(
@ -43,9 +43,9 @@ fn to_lower_case(
) -> SassResult<Value> { ) -> SassResult<Value> {
args.max_args(1)?; args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") { match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(mut i, q) => { Value::String(mut i, q) => {
i.make_ascii_lowercase(); i.make_ascii_lowercase();
Ok(Value::Ident(i, q)) Ok(Value::String(i, q))
} }
v => Err(( v => Err((
format!( format!(
@ -61,7 +61,7 @@ fn to_lower_case(
fn str_length(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn str_length(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(i, _) => Ok(Value::Dimension(
Number::from(i.chars().count()), Number::from(i.chars().count()),
Unit::None, Unit::None,
)), )),
@ -79,7 +79,7 @@ fn str_length(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
fn quote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn quote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(i, _) => Ok(Value::String(i, QuoteKind::Quoted)),
v => Err(( v => Err((
format!( format!(
"$string: {} is not a string.", "$string: {} is not a string.",
@ -94,7 +94,7 @@ fn quote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRe
fn unquote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn unquote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(..) => Ok(i.unquote()),
v => Err(( v => Err((
format!( format!(
"$string: {} is not a string.", "$string: {} is not a string.",
@ -109,7 +109,7 @@ fn unquote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sass
fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(s, q) => (s, q),
v => { v => {
return Err(( return Err((
format!( format!(
@ -195,9 +195,9 @@ fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
} }
if start > end || start > str_len { if start > end || start > str_len {
Ok(Value::Ident(String::new(), quotes)) Ok(Value::String(String::new(), quotes))
} else { } else {
Ok(Value::Ident( Ok(Value::String(
string string
.chars() .chars()
.skip(start - 1) .skip(start - 1)
@ -211,7 +211,7 @@ fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
fn str_index(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn str_index(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(i, _) => i,
v => { v => {
return Err(( return Err((
format!( format!(
@ -225,7 +225,7 @@ fn str_index(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
}; };
let substr = match arg!(args, scope, super_selector, 1, "substring") { let substr = match arg!(args, scope, super_selector, 1, "substring") {
Value::Ident(i, _) => i, Value::String(i, _) => i,
v => { v => {
return Err(( return Err((
format!( format!(
@ -247,7 +247,7 @@ fn str_index(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> { fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_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::String(i, q) => (i, q),
v => { v => {
return Err(( return Err((
format!( format!(
@ -261,7 +261,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
}; };
let substr = match arg!(args, scope, super_selector, 1, "insert") { let substr = match arg!(args, scope, super_selector, 1, "insert") {
Value::Ident(i, _) => i, Value::String(i, _) => i,
v => { v => {
return Err(( return Err((
format!( format!(
@ -299,7 +299,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
}; };
if s1.is_empty() { if s1.is_empty() {
return Ok(Value::Ident(substr, quotes)); return Ok(Value::String(substr, quotes));
} }
let len = s1.chars().count(); let len = s1.chars().count();
@ -342,7 +342,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
} }
}; };
Ok(Value::Ident(string, quotes)) Ok(Value::String(string, quotes))
} }
#[cfg(feature = "random")] #[cfg(feature = "random")]
@ -353,7 +353,7 @@ fn unique_id(args: CallArgs, _: &Scope, _: &Selector) -> SassResult<Value> {
.map(|()| rng.sample(Alphanumeric)) .map(|()| rng.sample(Alphanumeric))
.take(7) .take(7)
.collect(); .collect();
Ok(Value::Ident(string, QuoteKind::None)) Ok(Value::String(string, QuoteKind::None))
} }
pub(crate) fn declare(f: &mut GlobalFunctionMap) { pub(crate) fn declare(f: &mut GlobalFunctionMap) {

View File

@ -124,7 +124,7 @@ impl Attribute {
q @ '\'' | q @ '"' => { q @ '\'' | q @ '"' => {
toks.next(); toks.next();
match parse_quoted_string(toks, scope, q, super_selector)?.node { match parse_quoted_string(toks, scope, q, super_selector)?.node {
Value::Ident(s, ..) => s, Value::String(s, ..) => s,
_ => unreachable!(), _ => unreachable!(),
} }
} }
@ -180,7 +180,7 @@ impl Display for Attribute {
// or having special emitter for quoted strings? // or having special emitter for quoted strings?
// (also avoids the clone because we can consume/modify self) // (also avoids the clone because we can consume/modify self)
f.write_str( f.write_str(
&Value::Ident(self.value.clone(), QuoteKind::Quoted) &Value::String(self.value.clone(), QuoteKind::Quoted)
.to_css_string(self.span) .to_css_string(self.span)
.unwrap(), .unwrap(),
)?; )?;

View File

@ -57,7 +57,7 @@ impl SelectorPart {
Value::List( Value::List(
kinds kinds
.iter() .iter()
.map(|s| Value::Ident(s.to_string(), QuoteKind::None)) .map(|s| Value::String(s.to_string(), QuoteKind::None))
.collect(), .collect(),
ListSeparator::Space, ListSeparator::Space,
Brackets::None, Brackets::None,

View File

@ -213,7 +213,7 @@ pub(crate) fn eat_ident<I: Iterator<Item = Token>>(
toks.next(); toks.next();
text.push_str( text.push_str(
&match parse_interpolation(toks, scope, super_selector)?.node { &match parse_interpolation(toks, scope, super_selector)?.node {
Value::Ident(s, ..) => s, Value::String(s, ..) => s,
v => v.to_css_string(span)?.into(), v => v.to_css_string(span)?.into(),
}, },
); );
@ -291,7 +291,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
toks.next(); toks.next();
let interpolation = parse_interpolation(toks, scope, super_selector)?; let interpolation = parse_interpolation(toks, scope, super_selector)?;
s.push_str(&match interpolation.node { s.push_str(&match interpolation.node {
Value::Ident(s, ..) => s, Value::String(s, ..) => s,
v => v.to_css_string(interpolation.span)?.into(), v => v.to_css_string(interpolation.span)?.into(),
}); });
continue; continue;
@ -345,7 +345,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
} }
} }
Ok(Spanned { Ok(Spanned {
node: Value::Ident(s, QuoteKind::Quoted), node: Value::String(s, QuoteKind::Quoted),
span, span,
}) })
} }

View File

@ -113,7 +113,7 @@ pub(crate) fn try_eat_url<I: Iterator<Item = Token>>(
let (interpolation, count) = peek_interpolation(toks, scope, super_selector)?; let (interpolation, count) = peek_interpolation(toks, scope, super_selector)?;
peek_counter += count; peek_counter += count;
buf.push_str(&match interpolation.node { buf.push_str(&match interpolation.node {
Value::Ident(s, ..) => s, Value::String(s, ..) => s,
v => v.to_css_string(interpolation.span)?.into(), v => v.to_css_string(interpolation.span)?.into(),
}); });
} else { } else {

View File

@ -33,7 +33,7 @@ pub(crate) enum Value {
UnaryOp(Op, Box<Value>), UnaryOp(Op, Box<Value>),
BinaryOp(Box<Value>, Op, Box<Value>), BinaryOp(Box<Value>, Op, Box<Value>),
Paren(Box<Value>), Paren(Box<Value>),
Ident(String, QuoteKind), String(String, QuoteKind),
Map(SassMap), Map(SassMap),
ArgList(Vec<Spanned<Value>>), ArgList(Vec<Spanned<Value>>),
/// Returned by `get-function()` /// Returned by `get-function()`
@ -111,7 +111,7 @@ impl Value {
pub fn is_null(&self, span: Span) -> SassResult<bool> { pub fn is_null(&self, span: Span) -> SassResult<bool> {
Ok(match self { Ok(match self {
&Value::Null => true, &Value::Null => true,
Value::Ident(i, QuoteKind::None) if i.is_empty() => true, Value::String(i, QuoteKind::None) if i.is_empty() => true,
Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => { Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => {
self.clone().eval(span)?.is_null(span)? self.clone().eval(span)?.is_null(span)?
} }
@ -166,7 +166,7 @@ impl Value {
self.clone().eval(span)?.to_css_string(span)? self.clone().eval(span)?.to_css_string(span)?
} }
Self::Paren(val) => val.to_css_string(span)?, Self::Paren(val) => val.to_css_string(span)?,
Self::Ident(string, QuoteKind::None) => { Self::String(string, QuoteKind::None) => {
let mut after_newline = false; let mut after_newline = false;
let mut buf = String::with_capacity(string.len()); let mut buf = String::with_capacity(string.len());
for c in string.chars() { for c in string.chars() {
@ -188,7 +188,7 @@ impl Value {
} }
Cow::Owned(buf) Cow::Owned(buf)
} }
Self::Ident(string, QuoteKind::Quoted) => { Self::String(string, QuoteKind::Quoted) => {
let mut buf = String::with_capacity(string.len()); let mut buf = String::with_capacity(string.len());
visit_quoted_string(&mut buf, false, string)?; visit_quoted_string(&mut buf, false, string)?;
Cow::Owned(buf) Cow::Owned(buf)
@ -218,7 +218,7 @@ impl Value {
pub fn unquote(self) -> Self { pub fn unquote(self) -> Self {
match self { match self {
Self::Ident(s1, _) => Self::Ident(s1, QuoteKind::None), Self::String(s1, _) => Self::String(s1, QuoteKind::None),
Self::List(v, sep, bracket) => { Self::List(v, sep, bracket) => {
Self::List(v.into_iter().map(Value::unquote).collect(), sep, bracket) Self::List(v.into_iter().map(Value::unquote).collect(), sep, bracket)
} }
@ -233,7 +233,7 @@ impl Value {
pub fn kind(&self, span: Span) -> SassResult<&'static str> { pub fn kind(&self, span: Span) -> SassResult<&'static str> {
match self { match self {
Self::Color(..) => Ok("color"), Self::Color(..) => Ok("color"),
Self::Ident(..) | Self::Important => Ok("string"), Self::String(..) | Self::Important => Ok("string"),
Self::Dimension(..) => Ok("number"), Self::Dimension(..) => Ok("number"),
Self::List(..) => Ok("list"), Self::List(..) => Ok("list"),
Self::Function(..) => Ok("function"), Self::Function(..) => Ok("function"),
@ -249,7 +249,7 @@ impl Value {
pub fn is_special_function(&self) -> bool { pub fn is_special_function(&self) -> bool {
match self { match self {
Self::Ident(s, QuoteKind::None) => is_special_function(s), Self::String(s, QuoteKind::None) => is_special_function(s),
_ => false, _ => false,
} }
} }

View File

@ -16,8 +16,8 @@ impl Value {
let precedence = Op::Equal.precedence(); let precedence = Op::Equal.precedence();
Ok(Value::bool(match self { Ok(Value::bool(match self {
Self::Ident(s1, ..) => match other { Self::String(s1, ..) => match other {
Self::Ident(s2, ..) => s1 == s2, Self::String(s2, ..) => s1 == s2,
_ => false, _ => false,
}, },
Self::Dimension(n, unit) => match other { Self::Dimension(n, unit) => match other {
@ -66,8 +66,8 @@ impl Value {
let precedence = Op::Equal.precedence(); let precedence = Op::Equal.precedence();
Ok(Value::bool(match self { Ok(Value::bool(match self {
Self::Ident(s1, ..) => match other { Self::String(s1, ..) => match other {
Self::Ident(s2, ..) => s1 != s2, Self::String(s2, ..) => s1 != s2,
_ => true, _ => true,
}, },
Self::Dimension(n, unit) => match other { Self::Dimension(n, unit) => match other {
@ -111,7 +111,7 @@ impl Value {
pub fn unary_op_plus(self, span: Span) -> SassResult<Self> { pub fn unary_op_plus(self, span: Span) -> SassResult<Self> {
Ok(match self.eval(span)?.node { Ok(match self.eval(span)?.node {
v @ Value::Dimension(..) => v, v @ Value::Dimension(..) => v,
v => Value::Ident(format!("+{}", v.to_css_string(span)?), QuoteKind::None), v => Value::String(format!("+{}", v.to_css_string(span)?), QuoteKind::None),
}) })
} }
@ -258,12 +258,12 @@ impl Value {
Ok(match self { Ok(match self {
Self::Function(..) | Self::ArgList(..) | Self::Map(..) => todo!(), Self::Function(..) | Self::ArgList(..) | Self::Map(..) => todo!(),
Self::Important | Self::True | Self::False => match other { Self::Important | Self::True | Self::False => match other {
Self::Ident(s, QuoteKind::Quoted) => Value::Ident( Self::String(s, QuoteKind::Quoted) => Value::String(
format!("{}{}", self.to_css_string(span)?, s), format!("{}{}", self.to_css_string(span)?, s),
QuoteKind::Quoted, QuoteKind::Quoted,
), ),
Self::Null => Value::Ident(self.to_css_string(span)?.into(), QuoteKind::None), Self::Null => Value::String(self.to_css_string(span)?.into(), QuoteKind::None),
_ => Value::Ident( _ => Value::String(
format!( format!(
"{}{}", "{}{}",
self.to_css_string(span)?, self.to_css_string(span)?,
@ -274,7 +274,7 @@ impl Value {
}, },
Self::Null => match other { Self::Null => match other {
Self::Null => Self::Null, Self::Null => Self::Null,
_ => Value::Ident(other.to_css_string(span)?.into(), QuoteKind::None), _ => Value::String(other.to_css_string(span)?.into(), QuoteKind::None),
}, },
Self::Dimension(num, unit) => match other { Self::Dimension(num, unit) => match other {
Self::Dimension(num2, unit2) => { Self::Dimension(num2, unit2) => {
@ -299,13 +299,13 @@ impl Value {
) )
} }
} }
Self::Ident(s, q) => Value::Ident(format!("{}{}{}", num, unit, s), q), Self::String(s, q) => Value::String(format!("{}{}{}", num, unit, s), q),
Self::Null => Value::Ident(format!("{}{}", num, unit), QuoteKind::None), Self::Null => Value::String(format!("{}{}", num, unit), QuoteKind::None),
Self::List(..) => Value::Ident( Self::List(..) => Value::String(
format!("{}{}{}", num, unit, other.to_css_string(span)?), format!("{}{}{}", num, unit, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
Self::True | Self::False => Self::Ident( Self::True | Self::False => Self::String(
format!("{}{}{}", num, unit, other.to_css_string(span)?), format!("{}{}{}", num, unit, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
@ -323,9 +323,9 @@ impl Value {
} }
}, },
Self::Color(c) => match other { Self::Color(c) => match other {
Self::Ident(s, q) => Value::Ident(format!("{}{}", c, s), q), Self::String(s, q) => Value::String(format!("{}{}", c, s), q),
Self::Null => Value::Ident(c.to_string(), QuoteKind::None), Self::Null => Value::String(c.to_string(), QuoteKind::None),
Self::List(..) => Value::Ident( Self::List(..) => Value::String(
format!("{}{}", c, other.to_css_string(span)?), format!("{}{}", c, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
@ -362,14 +362,16 @@ impl Value {
} }
} }
Self::UnaryOp(..) | Self::Paren(..) => self.eval(span)?.node.add(other, span)?, Self::UnaryOp(..) | Self::Paren(..) => self.eval(span)?.node.add(other, span)?,
Self::Ident(text, quotes) => match other { Self::String(text, quotes) => match other {
Self::Ident(text2, ..) => Self::Ident(text + &text2, quotes), Self::String(text2, ..) => Self::String(text + &text2, quotes),
_ => Value::Ident(text + &other.to_css_string(span)?, quotes), _ => Value::String(text + &other.to_css_string(span)?, quotes),
}, },
Self::List(..) => match other { Self::List(..) => match other {
Self::Ident(s, q) => Value::Ident(format!("{}{}", self.to_css_string(span)?, s), q), Self::String(s, q) => {
Value::String(format!("{}{}", self.to_css_string(span)?, s), q)
}
Self::Paren(..) => (self.add(other.eval(span)?.node, span))?, Self::Paren(..) => (self.add(other.eval(span)?.node, span))?,
_ => Value::Ident( _ => Value::String(
format!( format!(
"{}{}", "{}{}",
self.to_css_string(span)?, self.to_css_string(span)?,
@ -411,21 +413,21 @@ impl Value {
) )
} }
} }
Self::List(..) => Value::Ident( Self::List(..) => Value::String(
format!("{}{}-{}", num, unit, other.to_css_string(span)?), format!("{}{}-{}", num, unit, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
Self::Ident(..) => Value::Ident( Self::String(..) => Value::String(
format!("{}{}-{}", num, unit, other.to_css_string(span)?), format!("{}{}-{}", num, unit, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
_ => todo!(), _ => todo!(),
}, },
Self::Color(c) => match other { Self::Color(c) => match other {
Self::Ident(s, q) => { Self::String(s, q) => {
Value::Ident(format!("{}-{}{}{}", c, q, s, q), QuoteKind::None) Value::String(format!("{}-{}{}{}", c, q, s, q), QuoteKind::None)
} }
Self::Null => Value::Ident(format!("{}-", c), QuoteKind::None), Self::Null => Value::String(format!("{}-", c), QuoteKind::None),
Self::Dimension(..) | Self::Color(..) => { Self::Dimension(..) | Self::Color(..) => {
return Err(( return Err((
format!( format!(
@ -437,7 +439,7 @@ impl Value {
) )
.into()) .into())
} }
_ => Value::Ident( _ => Value::String(
format!("{}-{}", c, other.to_css_string(span)?), format!("{}-{}", c, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
@ -463,7 +465,7 @@ impl Value {
} }
} }
Self::Paren(..) => self.eval(span)?.node.sub(other, span)?, Self::Paren(..) => self.eval(span)?.node.sub(other, span)?,
Self::Ident(..) => Self::Ident( Self::String(..) => Self::String(
format!( format!(
"{}-{}", "{}-{}",
self.to_css_string(span)?, self.to_css_string(span)?,
@ -472,11 +474,11 @@ impl Value {
QuoteKind::None, QuoteKind::None,
), ),
Self::List(..) => match other { Self::List(..) => match other {
Self::Ident(s, q) => Value::Ident( Self::String(s, q) => Value::String(
format!("{}-{}{}{}", self.to_css_string(span)?, q, s, q), format!("{}-{}{}{}", self.to_css_string(span)?, q, s, q),
QuoteKind::None, QuoteKind::None,
), ),
_ => Value::Ident( _ => Value::String(
format!( format!(
"{}-{}", "{}-{}",
self.to_css_string(span)?, self.to_css_string(span)?,
@ -486,14 +488,14 @@ impl Value {
), ),
}, },
_ => match other { _ => match other {
Self::Ident(s, q) => Value::Ident( Self::String(s, q) => Value::String(
format!("{}-{}{}{}", self.to_css_string(span)?, q, s, q), format!("{}-{}{}{}", self.to_css_string(span)?, q, s, q),
QuoteKind::None, QuoteKind::None,
), ),
Self::Null => { Self::Null => {
Value::Ident(format!("{}-", self.to_css_string(span)?), QuoteKind::None) Value::String(format!("{}-", self.to_css_string(span)?), QuoteKind::None)
} }
_ => Value::Ident( _ => Value::String(
format!( format!(
"{}-{}", "{}-{}",
self.to_css_string(span)?, self.to_css_string(span)?,
@ -604,8 +606,8 @@ impl Value {
) )
} }
} }
Self::Ident(s, q) => { Self::String(s, q) => {
Value::Ident(format!("{}{}/{}{}{}", num, unit, q, s, q), QuoteKind::None) Value::String(format!("{}{}/{}{}{}", num, unit, q, s, q), QuoteKind::None)
} }
Self::BinaryOp(..) | Self::Paren(..) => { Self::BinaryOp(..) | Self::Paren(..) => {
Self::Dimension(num, unit).div(other.eval(span)?.node, span)? Self::Dimension(num, unit).div(other.eval(span)?.node, span)?
@ -613,10 +615,10 @@ impl Value {
_ => todo!(), _ => todo!(),
}, },
Self::Color(c) => match other { Self::Color(c) => match other {
Self::Ident(s, q) => { Self::String(s, q) => {
Value::Ident(format!("{}/{}{}{}", c, q, s, q), QuoteKind::None) Value::String(format!("{}/{}{}{}", c, q, s, q), QuoteKind::None)
} }
Self::Null => Value::Ident(format!("{}/", c), QuoteKind::None), Self::Null => Value::String(format!("{}/", c), QuoteKind::None),
Self::Dimension(..) | Self::Color(..) => { Self::Dimension(..) | Self::Color(..) => {
return Err(( return Err((
format!( format!(
@ -628,7 +630,7 @@ impl Value {
) )
.into()) .into())
} }
_ => Value::Ident( _ => Value::String(
format!("{}/{}", c, other.to_css_string(span)?), format!("{}/{}", c, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
@ -654,8 +656,8 @@ impl Value {
} }
} }
Self::Paren(..) => self.eval(span)?.node.div(other, span)?, Self::Paren(..) => self.eval(span)?.node.div(other, span)?,
Self::Ident(s1, q1) => match other { Self::String(s1, q1) => match other {
Self::Ident(s2, q2) => Value::Ident( Self::String(s2, q2) => Value::String(
format!("{}{}{}/{}{}{}", q1, s1, q1, q2, s2, q2), format!("{}{}{}/{}{}{}", q1, s1, q1, q2, s2, q2),
QuoteKind::None, QuoteKind::None,
), ),
@ -663,22 +665,22 @@ impl Value {
| Self::True | Self::True
| Self::False | Self::False
| Self::Dimension(..) | Self::Dimension(..)
| Self::Color(..) => Value::Ident( | Self::Color(..) => Value::String(
format!("{}{}{}/{}", q1, s1, q1, other.to_css_string(span)?), format!("{}{}{}/{}", q1, s1, q1, other.to_css_string(span)?),
QuoteKind::None, QuoteKind::None,
), ),
Self::Null => Value::Ident(format!("{}{}{}/", q1, s1, q1), QuoteKind::None), Self::Null => Value::String(format!("{}{}{}/", q1, s1, q1), QuoteKind::None),
_ => todo!(), _ => todo!(),
}, },
_ => match other { _ => match other {
Self::Ident(s, q) => Value::Ident( Self::String(s, q) => Value::String(
format!("{}/{}{}{}", self.to_css_string(span)?, q, s, q), format!("{}/{}{}{}", self.to_css_string(span)?, q, s, q),
QuoteKind::None, QuoteKind::None,
), ),
Self::Null => { Self::Null => {
Value::Ident(format!("{}/", self.to_css_string(span)?), QuoteKind::None) Value::String(format!("{}/", self.to_css_string(span)?), QuoteKind::None)
} }
_ => Value::Ident( _ => Value::String(
format!( format!(
"{}/{}", "{}/{}",
self.to_css_string(span)?, self.to_css_string(span)?,
@ -736,7 +738,7 @@ impl Value {
pub fn neg(self, span: Span) -> SassResult<Self> { pub fn neg(self, span: Span) -> SassResult<Self> {
Ok(match self.eval(span)?.node { Ok(match self.eval(span)?.node {
Value::Dimension(n, u) => Value::Dimension(-n, u), Value::Dimension(n, u) => Value::Dimension(-n, u),
v => Value::Ident(format!("-{}", v.to_css_string(span)?), QuoteKind::None), v => Value::String(format!("-{}", v.to_css_string(span)?), QuoteKind::None),
}) })
} }
} }

View File

@ -58,7 +58,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
span = span.merge(i.span); span = span.merge(i.span);
} else { } else {
return Ok(Spanned { return Ok(Spanned {
node: Value::Ident(format!("#{}", i.node), QuoteKind::None), node: Value::String(format!("#{}", i.node), QuoteKind::None),
span: i.span, span: i.span,
}); });
} }
@ -67,7 +67,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
3 => { 3 => {
let v = match u16::from_str_radix(&s, 16) { let v = match u16::from_str_radix(&s, 16) {
Ok(a) => a, Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)), Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
}; };
let red = (((v & 0xf00) >> 8) * 0x11) as u8; let red = (((v & 0xf00) >> 8) * 0x11) as u8;
let green = (((v & 0x0f0) >> 4) * 0x11) as u8; let green = (((v & 0x0f0) >> 4) * 0x11) as u8;
@ -80,7 +80,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
4 => { 4 => {
let v = match u16::from_str_radix(&s, 16) { let v = match u16::from_str_radix(&s, 16) {
Ok(a) => a, Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)), Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
}; };
let red = (((v & 0xf000) >> 12) * 0x11) as u8; let red = (((v & 0xf000) >> 12) * 0x11) as u8;
let green = (((v & 0x0f00) >> 8) * 0x11) as u8; let green = (((v & 0x0f00) >> 8) * 0x11) as u8;
@ -98,7 +98,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
6 => { 6 => {
let v = match u32::from_str_radix(&s, 16) { let v = match u32::from_str_radix(&s, 16) {
Ok(a) => a, Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)), Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
}; };
let red = ((v & 0x00ff_0000) >> 16) as u8; let red = ((v & 0x00ff_0000) >> 16) as u8;
let green = ((v & 0x0000_ff00) >> 8) as u8; let green = ((v & 0x0000_ff00) >> 8) as u8;
@ -111,7 +111,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
8 => { 8 => {
let v = match u32::from_str_radix(&s, 16) { let v = match u32::from_str_radix(&s, 16) {
Ok(a) => a, Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)), Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
}; };
let red = ((v & 0xff00_0000) >> 24) as u8; let red = ((v & 0xff00_0000) >> 24) as u8;
let green = ((v & 0x00ff_0000) >> 16) as u8; let green = ((v & 0x00ff_0000) >> 16) as u8;
@ -264,7 +264,7 @@ fn eat_op<I: Iterator<Item = Token>>(
} else { } else {
devour_whitespace(iter); devour_whitespace(iter);
space_separated.push(Spanned { space_separated.push(Spanned {
node: Value::Ident( node: Value::String(
format!("/{}", right.node.to_css_string(right.span)?), format!("/{}", right.node.to_css_string(right.span)?),
QuoteKind::None, QuoteKind::None,
), ),
@ -309,7 +309,7 @@ fn eat_op<I: Iterator<Item = Token>>(
devour_whitespace(iter); devour_whitespace(iter);
// special case when the value is literally "and" or "or" // special case when the value is literally "and" or "or"
if iter.peek().is_none() { if iter.peek().is_none() {
space_separated.push(Value::Ident(op.to_string(), QuoteKind::None).span(op.span)); space_separated.push(Value::String(op.to_string(), QuoteKind::None).span(op.span));
} else if let Some(left) = space_separated.pop() { } else if let Some(left) = space_separated.pop() {
devour_whitespace(iter); devour_whitespace(iter);
let right = single_value(iter, scope, super_selector, left.span)?; let right = single_value(iter, scope, super_selector, left.span)?;
@ -371,31 +371,21 @@ fn single_value<I: Iterator<Item = Token>>(
devour_whitespace(iter); devour_whitespace(iter);
let val = single_value(iter, scope, super_selector, span)?; let val = single_value(iter, scope, super_selector, span)?;
Spanned { Spanned {
node: Value::Ident( node: Value::String(
format!("/{}", val.node.to_css_string(val.span)?), format!("/{}", val.node.to_css_string(val.span)?),
QuoteKind::None, QuoteKind::None,
), ),
span: next.span.merge(val.span), span: next.span.merge(val.span),
} }
} }
Op::And => { Op::And => Spanned {
Spanned { node: Value::String("and".into(), QuoteKind::None),
node: Value::Ident( span: next.span,
"and".into(), },
QuoteKind::None, Op::Or => Spanned {
), node: Value::String("or".into(), QuoteKind::None),
span: next.span, span: next.span,
} },
}
Op::Or => {
Spanned {
node: Value::Ident(
"or".into(),
QuoteKind::None,
),
span: next.span,
}
}
_ => { _ => {
return Err(("Expected expression.", next.span).into()); return Err(("Expected expression.", next.span).into());
} }
@ -577,7 +567,7 @@ impl Value {
s.push(':'); s.push(':');
s.push_str(&eat_progid(toks, scope, super_selector)?); s.push_str(&eat_progid(toks, scope, super_selector)?);
return Ok(Spanned { return Ok(Spanned {
node: IntermediateValue::Value(Value::Ident(s, QuoteKind::None)), node: IntermediateValue::Value(Value::String(s, QuoteKind::None)),
span, span,
}); });
} }
@ -617,7 +607,7 @@ impl Value {
), ),
} }
return Ok( return Ok(
IntermediateValue::Value(Value::Ident(s, QuoteKind::None)).span(span) IntermediateValue::Value(Value::String(s, QuoteKind::None)).span(span)
); );
} }
}, },
@ -644,7 +634,7 @@ impl Value {
"not" => IntermediateValue::Op(Op::Not), "not" => IntermediateValue::Op(Op::Not),
"and" => IntermediateValue::Op(Op::And), "and" => IntermediateValue::Op(Op::And),
"or" => IntermediateValue::Op(Op::Or), "or" => IntermediateValue::Op(Op::Or),
_ => IntermediateValue::Value(Value::Ident(s, QuoteKind::None)), _ => IntermediateValue::Value(Value::String(s, QuoteKind::None)),
} }
.span(span)) .span(span))
} }