mate_rs/mate.rs
1//
2// Copyright 2022-present theiskaa. All rights reserved.
3// Use of this source code is governed by MIT license
4// that can be found in the LICENSE file.
5//
6
7use crate::{calculator::Calculator, errors::Error, lexer::Lexer};
8
9// A main structure that takes string input, parses it via [Lexer],
10// and calculates result via [Calculator].
11pub struct Mate {}
12
13impl Mate {
14 // Takes a arithmetic expression as string, parses it to tokens, and calculates final result.
15 // Detailed descriptions could be viewed at lexer source file and calculator source file.
16 pub fn calculate(input: &str) -> Result<f64, Error> {
17 let sub = match Lexer::lex(input.clone()) {
18 Err(e) => return Err(e),
19 Ok(v) => v,
20 };
21
22 Calculator::calculate(sub, input.clone())
23 }
24}