Initial implementation of parens in Value
This commit is contained in:
parent
05503b3a16
commit
7fe9da3d2c
15
src/lib.rs
15
src/lib.rs
@ -1312,4 +1312,19 @@ mod test_values {
|
|||||||
"a {\n color: 1, 2, 3;\n}\n"
|
"a {\n color: 1, 2, 3;\n}\n"
|
||||||
);
|
);
|
||||||
test!(number, "a {\n color: 1;\n}\n");
|
test!(number, "a {\n color: 1;\n}\n");
|
||||||
|
test!(
|
||||||
|
removes_paren_around_single_value,
|
||||||
|
"a {\n color: (red);\n}\n",
|
||||||
|
"a {\n color: red;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
removes_paren_around_space_list,
|
||||||
|
"a {\n color: (red blue);\n}\n",
|
||||||
|
"a {\n color: red blue;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
removes_paren_around_item_in_list,
|
||||||
|
"a {\n color: 1 (red blue);\n}\n",
|
||||||
|
"a {\n color: 1 red blue;\n}\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
12
src/value.rs
12
src/value.rs
@ -127,7 +127,7 @@ impl Display for Value {
|
|||||||
.join(sep.as_str())
|
.join(sep.as_str())
|
||||||
),
|
),
|
||||||
Self::Color(c) => write!(f, "{}", c),
|
Self::Color(c) => write!(f, "{}", c),
|
||||||
Self::Paren(val) => write!(f, "({})", val),
|
Self::Paren(val) => write!(f, "{}", val),
|
||||||
Self::Ident(val, kind) => write!(f, "{}{}{}", kind.as_str(), val, kind.as_str()),
|
Self::Ident(val, kind) => write!(f, "{}{}{}", kind.as_str(), val, kind.as_str()),
|
||||||
Self::True => write!(f, "true"),
|
Self::True => write!(f, "true"),
|
||||||
Self::False => write!(f, "false"),
|
Self::False => write!(f, "false"),
|
||||||
@ -165,6 +165,7 @@ impl Value {
|
|||||||
};
|
};
|
||||||
Some(Value::List(vec![left, right], ListSeparator::Comma))
|
Some(Value::List(vec![left, right], ListSeparator::Comma))
|
||||||
}
|
}
|
||||||
|
TokenKind::Symbol(Symbol::CloseParen) => Some(left),
|
||||||
TokenKind::Symbol(Symbol::Plus) => {
|
TokenKind::Symbol(Symbol::Plus) => {
|
||||||
toks.next();
|
toks.next();
|
||||||
devour_whitespace_or_comment(toks);
|
devour_whitespace_or_comment(toks);
|
||||||
@ -222,6 +223,15 @@ impl Value {
|
|||||||
unit,
|
unit,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
TokenKind::Symbol(Symbol::OpenParen) => {
|
||||||
|
devour_whitespace_or_comment(toks);
|
||||||
|
let val = Self::from_tokens(toks, scope)?;
|
||||||
|
assert_eq!(
|
||||||
|
toks.next().unwrap().kind,
|
||||||
|
TokenKind::Symbol(Symbol::CloseParen)
|
||||||
|
);
|
||||||
|
Some(Value::Paren(Box::new(val)))
|
||||||
|
}
|
||||||
TokenKind::Ident(mut s) => {
|
TokenKind::Ident(mut s) => {
|
||||||
while let Some(tok) = toks.peek() {
|
while let Some(tok) = toks.peek() {
|
||||||
match tok.kind.clone() {
|
match tok.kind.clone() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user