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()
.take(5)
.collect(),
pos: self.pos })
pos: self.pos,
})
} else {
// If at the end of the input
Ok(None)
@ -136,4 +137,4 @@ mod test {
assert!(matches!(lexer.next(), Ok(Some(Token::CBR(TokenMeta { pos: 36 })))));
assert!(matches!(lexer.next(), Ok(None)));
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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