Crates.io | asciimath |
lib.rs | asciimath |
version | 0.8.8 |
source | src |
created_at | 2018-04-27 03:23:56.887875 |
updated_at | 2019-06-20 03:52:52.65056 |
description | Mathematical expression parser and evaluator |
homepage | https://github.com/chmln/asciimath-rs |
repository | https://github.com/chmln/asciimath-rs.git |
max_upload_size | |
id | 62516 |
size | 44,188 |
Sample use:
use asciimath::{eval, scope, CustomFn};
let my_sum: CustomFn = |args| Ok(args.iter().sum());
let scope = scope!{
"x" => -1,
"my_sum" => my_sum,
};
assert_eq!(Ok(260.0), eval("my_sum(1, ((1 - x) ^ 2 ^ 3), 3)", &scope));
Ease of use
This means that e.g. passing in variables to expressions and defining custom functions must be possible with minimum knowledge of this library's internals and abstractions. Errors must be helpful and relevant.
Minimalism
Focusing just on mathematical expressions will make it easy for this library to remain slim and deliver superior ergonomics.
Accuracy
Extensive testing and maximum precision must be a part of all the modules to prevent bugs and ensure consistency.
The items below will be considered after stabilization:
While some great libraries aiming for similar goals do exist, they wouldn't reward me with such a fruitful Rust learning experience and imo sorely lack ergonomics.
The parser is loosely based on Dijkstra's "shunting yard" algorithm for converting infix expressions into postfix expressions. However, instead of going from infix to postfix strings, we parse the expression straight into an Abstract Syntax Tree.