refactor: auto re-formatted the code

This commit is contained in:
Yandrik 2021-11-29 23:43:52 +01:00
parent 3240a28d7f
commit e0e1bc8340
7 changed files with 17 additions and 23 deletions

View File

@ -1,7 +0,0 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum CalculatorErrors {
#[error("IOError")]
IOError,
}

View File

@ -52,7 +52,8 @@ impl Lexer {
.iter() .iter()
.take(5) .take(5)
.collect(), .collect(),
pos: self.pos }) pos: self.pos,
})
} else { } else {
// If at the end of the input // If at the end of the input
Ok(None) Ok(None)
@ -136,4 +137,4 @@ mod test {
assert!(matches!(lexer.next(), Ok(Some(Token::CBR(TokenMeta { pos: 36 }))))); assert!(matches!(lexer.next(), Ok(Some(Token::CBR(TokenMeta { pos: 36 })))));
assert!(matches!(lexer.next(), Ok(None))); assert!(matches!(lexer.next(), Ok(None)));
} }
} }

View File

@ -1,4 +1,3 @@
/// # Token Metadata /// # Token Metadata
/// Data contained is: /// Data contained is:
/// * File that the token was parsed in /// * File that the token was parsed in
@ -27,7 +26,7 @@ impl OpType {
'+' => Some(OpType::ADD), '+' => Some(OpType::ADD),
'-' => Some(OpType::SUB), '-' => Some(OpType::SUB),
'^' => Some(OpType::POW), '^' => Some(OpType::POW),
_ => None, _ => None,
} }
} }
} }
@ -47,8 +46,8 @@ pub enum BrType {
/// 1. `OP`: An operation. Containing an [Operation Type](OpType). /// 1. `OP`: An operation. Containing an [Operation Type](OpType).
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Token { pub enum Token {
ID (TokenMeta, f64), ID(TokenMeta, f64),
OBR (TokenMeta), OBR(TokenMeta),
CBR (TokenMeta), CBR(TokenMeta),
OP (TokenMeta, OpType), OP(TokenMeta, OpType),
} }

View File

@ -1,9 +1,9 @@
mod lexer;
mod parser;
pub use lexer::errors as lexer_errors; pub use lexer::errors as lexer_errors;
pub use parser::errors as parser_errors; pub use parser::errors as parser_errors;
mod lexer;
mod parser;
pub fn calculate(expression: &str) -> Result<f64, parser::errors::ParserErrors> { pub fn calculate(expression: &str) -> Result<f64, parser::errors::ParserErrors> {
Ok(parser::parse(lexer::Lexer::new(expression))?) Ok(parser::parse(lexer::Lexer::new(expression))?)
} }

View File

@ -1,5 +1,6 @@
use std::io; use std::io;
use std::io::Write; use std::io::Write;
use s5_cb_calculator::calculate; use s5_cb_calculator::calculate;
fn main() { fn main() {
@ -17,5 +18,4 @@ fn main() {
Err(err) => println!("Expression couldn't be parsed: {:?}", err) Err(err) => println!("Expression couldn't be parsed: {:?}", err)
} }
} }
} }

View File

@ -1,4 +1,5 @@
use thiserror::Error; use thiserror::Error;
use crate::lexer::errors::LexerErrors; use crate::lexer::errors::LexerErrors;
use crate::lexer::tokens::Token; use crate::lexer::tokens::Token;

View File

@ -65,7 +65,7 @@ fn a_proc(tbox: &mut TokenBox) -> Result<f64> {
Some(token) => { Some(token) => {
tbox.regress(); tbox.regress();
Ok(result) Ok(result)
}, }
} }
} }
@ -79,7 +79,7 @@ fn m_proc(tbox: &mut TokenBox) -> Result<f64> {
Some(token) => { Some(token) => {
tbox.regress(); tbox.regress();
Ok(result) Ok(result)
}, }
} }
} }
@ -92,7 +92,7 @@ fn g_proc(tbox: &mut TokenBox) -> Result<f64> {
Some(token) => { Some(token) => {
tbox.regress(); tbox.regress();
Ok(result) Ok(result)
}, }
} }
} }
@ -105,7 +105,7 @@ fn p_proc(tbox: &mut TokenBox) -> Result<f64> {
Token::CBR(_) => Ok(result), Token::CBR(_) => Ok(result),
token => Err(UnexpectedTokenError(token.clone(), String::from("P"))), token => Err(UnexpectedTokenError(token.clone(), String::from("P"))),
} }
}, }
Token::ID(_, val) => Ok(*val), Token::ID(_, val) => Ok(*val),
token => Err(ParserErrors::UnexpectedTokenError(token.clone(), String::from("P"))), token => Err(ParserErrors::UnexpectedTokenError(token.clone(), String::from("P"))),
} }