refactor parser return

This commit is contained in:
Ivan Tham 2020-08-01 16:51:07 +08:00 committed by Connor Skees
parent edec89093b
commit c5814a4a06

View File

@ -330,27 +330,24 @@ impl<'a> Parser<'a> {
}
// check for named colors
if let Some(c) = NAMED_COLORS.get_by_name(lower.as_str()) {
return Ok(
IntermediateValue::Value(HigherIntermediateValue::Literal(Value::Color(Box::new(
Color::new(c[0], c[1], c[2], c[3], s),
))))
.span(span),
);
}
// check for keywords
Ok(match s.as_str() {
"true" => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::True)),
"false" => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::False)),
"null" => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::Null)),
"not" => IntermediateValue::Op(Op::Not),
"and" => IntermediateValue::Op(Op::And),
"or" => IntermediateValue::Op(Op::Or),
_ => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::String(
s,
QuoteKind::None,
))),
Ok(if let Some(c) = NAMED_COLORS.get_by_name(lower.as_str()) {
IntermediateValue::Value(HigherIntermediateValue::Literal(Value::Color(Box::new(
Color::new(c[0], c[1], c[2], c[3], s),
))))
} else {
// check for keywords
match s.as_str() {
"true" => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::True)),
"false" => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::False)),
"null" => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::Null)),
"not" => IntermediateValue::Op(Op::Not),
"and" => IntermediateValue::Op(Op::And),
"or" => IntermediateValue::Op(Op::Or),
_ => IntermediateValue::Value(HigherIntermediateValue::Literal(Value::String(
s,
QuoteKind::None,
))),
}
}
.span(span))
}