Implement addition between colors and idents
This commit is contained in:
parent
901c911b5b
commit
2b3d8fcce7
@ -1,5 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::convert::TryInto;
|
|
||||||
|
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
|
@ -24,7 +24,14 @@ impl Add for Value {
|
|||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
},
|
},
|
||||||
// Self::List(..) => todo!(),
|
// Self::List(..) => todo!(),
|
||||||
// Self::Color(..) => todo!(),
|
Self::Color(c) => match other {
|
||||||
|
Self::Ident(s, QuoteKind::Double) | Self::Ident(s, QuoteKind::Single) => {
|
||||||
|
Value::Ident(format!("{}{}", c, s), QuoteKind::Double)
|
||||||
|
}
|
||||||
|
Self::Null => Value::Ident(c.to_string(), QuoteKind::None),
|
||||||
|
Self::Color(..) => todo!("figure out if it's possible to add colors"),
|
||||||
|
_ => Value::Ident(format!("{}{}", c, other), QuoteKind::None),
|
||||||
|
}
|
||||||
// Self::BinaryOp(..) => todo!(),
|
// Self::BinaryOp(..) => todo!(),
|
||||||
// Self::Paren(..) => todo!(),
|
// Self::Paren(..) => todo!(),
|
||||||
Self::Ident(s1, quotes1) => match other {
|
Self::Ident(s1, quotes1) => match other {
|
||||||
@ -52,6 +59,13 @@ impl Add for Value {
|
|||||||
};
|
};
|
||||||
Value::Ident(s1, quotes)
|
Value::Ident(s1, quotes)
|
||||||
}
|
}
|
||||||
|
Self::Color(c) => {
|
||||||
|
let quotes = match quotes1 {
|
||||||
|
QuoteKind::Double | QuoteKind::Single => QuoteKind::Double,
|
||||||
|
QuoteKind::None => QuoteKind::None,
|
||||||
|
};
|
||||||
|
Value::Ident(format!("{}{}", s1, c), quotes)
|
||||||
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
},
|
},
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
|
@ -116,3 +116,23 @@ test!(
|
|||||||
"a {\n color: hsla($hue: 193, $saturation: 67%, $luminance: 99, $alpha: .6);\n}\n",
|
"a {\n color: hsla($hue: 193, $saturation: 67%, $luminance: 99, $alpha: .6);\n}\n",
|
||||||
"a {\n color: rgba(251, 253, 254, 0.6);\n}\n"
|
"a {\n color: rgba(251, 253, 254, 0.6);\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
color_plus_ident,
|
||||||
|
"a {\n color: red + foo;\n}\n",
|
||||||
|
"a {\n color: redfoo;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
ident_plus_color,
|
||||||
|
"a {\n color: foo + red;\n}\n",
|
||||||
|
"a {\n color: foored;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
color_minus_ident,
|
||||||
|
"a {\n color: red - foo;\n}\n",
|
||||||
|
"a {\n color: red-foo;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
ident_minus_color,
|
||||||
|
"a {\n color: foo - red;\n}\n",
|
||||||
|
"a {\n color: foo-red;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user