expressive/src/lib.rs

29 lines
692 B
Rust
Raw Normal View History

use configuration::EmptyConfiguration;
use error::Error;
use value::Value;
2016-11-16 16:12:26 +00:00
mod configuration;
mod error;
2016-11-16 16:12:26 +00:00
mod operator;
mod token;
mod tree;
mod value;
2019-03-15 11:42:18 +00:00
pub fn eval(string: &str) -> Result<Value, Error> {
tree::tokens_to_operator_tree(token::tokenize(string))?.eval(&EmptyConfiguration)
}
2016-11-16 16:12:26 +00:00
#[cfg(test)]
mod test {
use crate::{eval, value::Value};
2016-11-16 16:12:26 +00:00
#[test]
fn test_simple_examples() {
assert_eq!(eval("3"), Ok(Value::Number(3.0)));
assert_eq!(eval("1+3"), Ok(Value::Number(4.0)));
assert_eq!(eval("3+1"), Ok(Value::Number(4.0)));
assert_eq!(eval("3-5"), Ok(Value::Number(-2.0)));
assert_eq!(eval("5-3"), Ok(Value::Number(2.0)));
2016-11-16 16:12:26 +00:00
}
}