From 6c6bac142b5bb04cb7505af1a0c947bdc162a967 Mon Sep 17 00:00:00 2001 From: vanten-s Date: Sat, 16 Sep 2023 23:44:28 +0200 Subject: [PATCH] Slight refactor --- src/tokeniser.rs | 49 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/tokeniser.rs b/src/tokeniser.rs index 9eb505e..db94792 100644 --- a/src/tokeniser.rs +++ b/src/tokeniser.rs @@ -80,41 +80,24 @@ fn tokenise_current_character( return Unfinished(Some(Token::Identifier(String::from(current_character)))); } - if current_character == ';' { - return Unfinished(Some(Token::Semi)); - } + { + use std::option::Option::Some as s; + use Token as T; + use TokenFinishedUnfinished::Unfinished as uf; - if current_character == '(' { - return Unfinished(Some(Token::OpenParanthesis)); + match current_character { + ';' => uf(s(T::Semi)), + '(' => uf(s(T::OpenParanthesis)), + ')' => uf(s(T::CloseParanthesis)), + '{' => uf(s(T::OpenSquiglyBracket)), + '}' => uf(s(T::CloseSquiglyBracket)), + '=' => uf(s(T::Equals)), + ',' => uf(s(T::Comma)), + '+' => uf(s(T::Plus)), + '-' => uf(s(T::Minus)), + _ => uf(None), + } } - if current_character == ')' { - return Unfinished(Some(Token::CloseParanthesis)); - } - - if current_character == '{' { - return Unfinished(Some(Token::OpenSquiglyBracket)); - } - if current_character == '}' { - return Unfinished(Some(Token::CloseSquiglyBracket)); - } - - if current_character == '=' { - return Unfinished(Some(Token::Equals)); - } - - if current_character == ',' { - return Unfinished(Some(Token::Comma)); - } - - if current_character == '+' { - return Unfinished(Some(Token::Plus)); - } - - if current_character == '-' { - return Unfinished(Some(Token::Minus)); - } - - Unfinished(None) } Some(v) => Finished(v), }