tcalc_core 0.1.1

Core library for tcalc-cli crate.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pub mod evaluator;
pub mod lexer;
pub mod parser;

use crate::evaluator::eval;
use crate::lexer::Lexer;
use crate::parser::parse;

pub fn run(input: &str) -> Result<String, String> {
    let tokens = Lexer::new(input);
    let ast = parse(tokens).map_err(|err| format!("failed to parse expression: {}", err))?;
    let result = eval(&ast).map_err(|err| format!("failed to evaluate expression: {}", err))?;
    Ok(result.to_string())
}