fengcen / eval Goto Github PK
View Code? Open in Web Editor NEW[ABANDONED] Expression evaluator for Rust
License: MIT License
[ABANDONED] Expression evaluator for Rust
License: MIT License
example:
eval("2 * 4 + 4")
will correctly evaluate to 12 while eval("2 * (2 + 2) + (1 + 3)")
or even eval(2 * (4) + (4))
will evaluate to 16, even though the two expressions should have the same result.
fn main() {
assert_eq!(eval("2 * 4 + 4"), Ok(to_value(12)));
assert_eq!(eval("2 * (4) + (4)"), Ok(to_value(12)));
}
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Ok(Number(16))`,
right: `Ok(Number(12))`', src/main.rs:7:5
Evaluation order seems to be wrong when the dot operator is used.
#[test]
fn test_operator_precedence() {
// Show that operator precedence is working as expected.
assert_eq!(eval(r#""a" == "a" && "b" == "b""#), Ok(to_value(true)));
let mut v = HashMap::new();
v.insert("a", "1");
v.insert("b", "2");
// This is returning the expected result if we put the comparisons between parentheses.
assert_eq!(Expr::new("(v.a == v.a) && (v.b == v.b)").value("v", v.clone()).exec(),
Ok(to_value(true)));
// This should return the same result as the previous Expr, but it is instead
// returning Err(UnsupportedTypes("String(\"1\")", "Bool(true)")).
assert_eq!(Expr::new("v.a == v.a && v.b == v.b").value("v", v).exec(),
Ok(to_value(true)));
}
eval("-5")
results in Err(StartWithNonValueOperator)
eval("5*-5")
results in Err(DuplicateOperatorNode)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.