From 00aeacbc7495e3d1a7aac2e979faeb6460eb112c Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 1 Aug 2020 16:51:07 +0800 Subject: [PATCH] refactor parser return --- src/parse/value/parse.rs | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/parse/value/parse.rs b/src/parse/value/parse.rs index f1483cb..d365957 100644 --- a/src/parse/value/parse.rs +++ b/src/parse/value/parse.rs @@ -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)) }