From 5f68bc7c008b18a498e043332559a9200d8ed115 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 26 Jul 2023 14:53:50 +0300 Subject: [PATCH] Fix formatting. --- src/token/mod.rs | 225 +++++++++++++++++++++++------------------------ 1 file changed, 111 insertions(+), 114 deletions(-) diff --git a/src/token/mod.rs b/src/token/mod.rs index b8102d5..e086073 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -298,139 +298,136 @@ fn partial_tokens_to_tokens(mut tokens: &[PartialToken]) -> EvalexprResult { + result.extend(match first { + PartialToken::Token(token) => { + cutoff = 1; + Some(token) + }, + PartialToken::Plus => match second { + Some(PartialToken::Eq) => Some(Token::PlusAssign), + _ => { cutoff = 1; - Some(token) - }, - PartialToken::Plus => match second { - Some(PartialToken::Eq) => Some(Token::PlusAssign), - _ => { - cutoff = 1; - Some(Token::Plus) - }, + Some(Token::Plus) }, - PartialToken::Minus => match second { - Some(PartialToken::Eq) => Some(Token::MinusAssign), - _ => { - cutoff = 1; - Some(Token::Minus) - }, - }, - PartialToken::Star => match second { - Some(PartialToken::Eq) => Some(Token::StarAssign), - _ => { - cutoff = 1; - Some(Token::Star) - }, + }, + PartialToken::Minus => match second { + Some(PartialToken::Eq) => Some(Token::MinusAssign), + _ => { + cutoff = 1; + Some(Token::Minus) }, - PartialToken::Slash => match second { - Some(PartialToken::Eq) => Some(Token::SlashAssign), - _ => { - cutoff = 1; - Some(Token::Slash) - }, + }, + PartialToken::Star => match second { + Some(PartialToken::Eq) => Some(Token::StarAssign), + _ => { + cutoff = 1; + Some(Token::Star) }, - PartialToken::Percent => match second { - Some(PartialToken::Eq) => Some(Token::PercentAssign), - _ => { - cutoff = 1; - Some(Token::Percent) - }, + }, + PartialToken::Slash => match second { + Some(PartialToken::Eq) => Some(Token::SlashAssign), + _ => { + cutoff = 1; + Some(Token::Slash) }, - PartialToken::Hat => match second { - Some(PartialToken::Eq) => Some(Token::HatAssign), - _ => { - cutoff = 1; - Some(Token::Hat) - }, + }, + PartialToken::Percent => match second { + Some(PartialToken::Eq) => Some(Token::PercentAssign), + _ => { + cutoff = 1; + Some(Token::Percent) }, - PartialToken::Literal(literal) => { + }, + PartialToken::Hat => match second { + Some(PartialToken::Eq) => Some(Token::HatAssign), + _ => { cutoff = 1; - if let Ok(number) = parse_dec_or_hex(&literal) { - Some(Token::Int(number)) - } else if let Ok(number) = literal.parse::() { - Some(Token::Float(number)) - } else if let Ok(boolean) = literal.parse::() { - Some(Token::Boolean(boolean)) - } else { - // If there are two tokens following this one, check if the next one is - // a plus or a minus. If so, then attempt to parse all three tokens as a - // scientific notation number of the form `e{+,-}`, - // for example [Literal("10e"), Minus, Literal("3")] => "1e-3".parse(). - match (second, third) { - (Some(second), Some(third)) - if second == PartialToken::Minus - || second == PartialToken::Plus => + Some(Token::Hat) + }, + }, + PartialToken::Literal(literal) => { + cutoff = 1; + if let Ok(number) = parse_dec_or_hex(&literal) { + Some(Token::Int(number)) + } else if let Ok(number) = literal.parse::() { + Some(Token::Float(number)) + } else if let Ok(boolean) = literal.parse::() { + Some(Token::Boolean(boolean)) + } else { + // If there are two tokens following this one, check if the next one is + // a plus or a minus. If so, then attempt to parse all three tokens as a + // scientific notation number of the form `e{+,-}`, + // for example [Literal("10e"), Minus, Literal("3")] => "1e-3".parse(). + match (second, third) { + (Some(second), Some(third)) + if second == PartialToken::Minus || second == PartialToken::Plus => + { + if let Ok(number) = + format!("{}{}{}", literal, second, third).parse::() { - if let Ok(number) = - format!("{}{}{}", literal, second, third).parse::() - { - cutoff = 3; - Some(Token::Float(number)) - } else { - Some(Token::Identifier(literal.to_string())) - } - }, - _ => Some(Token::Identifier(literal.to_string())), - } + cutoff = 3; + Some(Token::Float(number)) + } else { + Some(Token::Identifier(literal.to_string())) + } + }, + _ => Some(Token::Identifier(literal.to_string())), } - }, - PartialToken::Whitespace => { + } + }, + PartialToken::Whitespace => { + cutoff = 1; + None + }, + PartialToken::Eq => match second { + Some(PartialToken::Eq) => Some(Token::Eq), + _ => { cutoff = 1; - None - }, - PartialToken::Eq => match second { - Some(PartialToken::Eq) => Some(Token::Eq), - _ => { - cutoff = 1; - Some(Token::Assign) - }, + Some(Token::Assign) }, - PartialToken::ExclamationMark => match second { - Some(PartialToken::Eq) => Some(Token::Neq), - _ => { - cutoff = 1; - Some(Token::Not) - }, + }, + PartialToken::ExclamationMark => match second { + Some(PartialToken::Eq) => Some(Token::Neq), + _ => { + cutoff = 1; + Some(Token::Not) }, - PartialToken::Gt => match second { - Some(PartialToken::Eq) => Some(Token::Geq), - _ => { - cutoff = 1; - Some(Token::Gt) - }, + }, + PartialToken::Gt => match second { + Some(PartialToken::Eq) => Some(Token::Geq), + _ => { + cutoff = 1; + Some(Token::Gt) }, - PartialToken::Lt => match second { - Some(PartialToken::Eq) => Some(Token::Leq), - _ => { - cutoff = 1; - Some(Token::Lt) - }, + }, + PartialToken::Lt => match second { + Some(PartialToken::Eq) => Some(Token::Leq), + _ => { + cutoff = 1; + Some(Token::Lt) }, - PartialToken::Ampersand => match second { - Some(PartialToken::Ampersand) => match third { - Some(PartialToken::Eq) => { - cutoff = 3; - Some(Token::AndAssign) - }, - _ => Some(Token::And), + }, + PartialToken::Ampersand => match second { + Some(PartialToken::Ampersand) => match third { + Some(PartialToken::Eq) => { + cutoff = 3; + Some(Token::AndAssign) }, - _ => return Err(EvalexprError::unmatched_partial_token(first, second)), + _ => Some(Token::And), }, - PartialToken::VerticalBar => match second { - Some(PartialToken::VerticalBar) => match third { - Some(PartialToken::Eq) => { - cutoff = 3; - Some(Token::OrAssign) - }, - _ => Some(Token::Or), + _ => return Err(EvalexprError::unmatched_partial_token(first, second)), + }, + PartialToken::VerticalBar => match second { + Some(PartialToken::VerticalBar) => match third { + Some(PartialToken::Eq) => { + cutoff = 3; + Some(Token::OrAssign) }, - _ => return Err(EvalexprError::unmatched_partial_token(first, second)), + _ => Some(Token::Or), }, + _ => return Err(EvalexprError::unmatched_partial_token(first, second)), }, - ); + }); tokens = &tokens[cutoff..]; }