more robustly parse empty bracketed lists

This commit is contained in:
Connor Skees 2020-07-03 23:49:31 -04:00
parent 28fa06a85f
commit efc5f91348
3 changed files with 25 additions and 12 deletions

View File

@ -1,3 +1,7 @@
# TBD
- more robustly parse empty bracketed lists
# 0.9.2
- implement builtin functions `min` and `max`

View File

@ -112,17 +112,6 @@ impl<'a> Parser<'a> {
}
IntermediateValue::Bracketed(t) => {
last_was_whitespace = false;
if t.is_empty() {
space_separated.push(
HigherIntermediateValue::Literal(Value::List(
Vec::new(),
ListSeparator::Space,
Brackets::Bracketed,
))
.span(val.span),
);
continue;
}
space_separated.push(
HigherIntermediateValue::Literal(
match iter.parser.parse_value_from_vec(t)?.node {
@ -509,6 +498,7 @@ impl<'a> Parser<'a> {
}
'[' => {
let mut span = self.toks.next().unwrap().pos();
self.whitespace_or_comment();
let mut inner = match read_until_closing_square_brace(self.toks) {
Ok(v) => v,
Err(e) => return Some(Err(e)),
@ -519,7 +509,16 @@ impl<'a> Parser<'a> {
}
span = span.merge(last_tok.pos());
}
IntermediateValue::Bracketed(inner).span(span)
if inner.is_empty() {
IntermediateValue::Value(HigherIntermediateValue::Literal(Value::List(
Vec::new(),
ListSeparator::Space,
Brackets::Bracketed,
)))
} else {
IntermediateValue::Bracketed(inner)
}
.span(span)
}
'$' => {
self.toks.next();

View File

@ -314,6 +314,16 @@ test!(
"a {\n color: 3;\n}\n"
);
test!(empty_bracketed_list, "a {\n empty: [];\n}\n");
test!(
empty_bracketed_list_equality,
"a {\n color: []==[];\n}\n",
"a {\n color: true;\n}\n"
);
test!(
empty_bracketed_list_whitespace,
"a {\n color: [ /**/ ];\n}\n",
"a {\n color: [];\n}\n"
);
error!(
invalid_item_in_space_separated_list,
"a {\n color: red color * #abc;\n}\n", "Error: Undefined operation \"color * #abc\"."