refactor parser return

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

View File

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