-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start of parser * ops forgot * reorder files and work on executer * start of parser * ops forgot * reorder files and work on executer * Cleanup and fix tests * Integrate into the editor * added unit checking at parse time * fix tests * fix issues * fix editor intergration * update pest grammer to support units * units should be working, need to set up tests to know * make unit type store exponants as i32 * remove scale, insted just multiply the literal by the scale * unit now contains empty unit,remove options * add more tests and implement almost all unary operators * add evaluation context and variables * function calling, api might be refined later * add constants, change function call to not be as built into the parser and add tests * add function definitions * remove meval * remove raw-rs from workspace * add support for numberless units * fix unit handleing logic, add some "unit" tests(haha) * make it so units cant do implcit mul with idents * add bench and better tests * fix editor api * remove old test * change hashmap context to use deref * change constants to use hashmap instad of function --------- Co-authored-by: hypercube <[email protected]> Co-authored-by: Keavon Chambers <[email protected]>
- Loading branch information
1 parent
51ce51e
commit 9fb4947
Showing
14 changed files
with
1,260 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "math-parser" | ||
version = "0.0.0" | ||
rust-version = "1.79" | ||
edition = "2021" | ||
authors = ["Graphite Authors <[email protected]>"] | ||
description = "Parser for Graphite style mathematics expressions" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[dependencies] | ||
pest = "2.7" | ||
pest_derive = "2.7.11" | ||
thiserror = "1" | ||
lazy_static = "1.5" | ||
num-complex = "0.4" | ||
log = { workspace = true } | ||
|
||
[dev-dependencies] | ||
criterion = "0.5" | ||
|
||
[[bench]] | ||
name = "bench" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
use math_parser::ast; | ||
use math_parser::context::EvalContext; | ||
|
||
macro_rules! generate_benchmarks { | ||
($( $input:expr ),* $(,)?) => { | ||
fn parsing_bench(c: &mut Criterion) { | ||
$( | ||
c.bench_function(concat!("parse ", $input), |b| { | ||
b.iter(|| { | ||
let _ = black_box(ast::Node::from_str($input)).unwrap(); | ||
}); | ||
}); | ||
)* | ||
} | ||
|
||
fn evaluation_bench(c: &mut Criterion) { | ||
$( | ||
let expr = ast::Node::from_str($input).unwrap().0; | ||
let context = EvalContext::default(); | ||
|
||
c.bench_function(concat!("eval ", $input), |b| { | ||
b.iter(|| { | ||
let _ = black_box(expr.eval(&context)); | ||
}); | ||
}); | ||
)* | ||
} | ||
|
||
criterion_group!(benches, parsing_bench, evaluation_bench); | ||
criterion_main!(benches); | ||
}; | ||
} | ||
|
||
generate_benchmarks! { | ||
"(3 * (4 + sqrt(25)) - cos(pi/3) * (2^3)) + 5 * e", // Mixed nested functions, constants, and operations | ||
"((5 + 2 * (3 - sqrt(49)))^2) / (1 + sqrt(16)) + tau / 2", // Complex nested expression with constants | ||
"log(100, 10) + (5 * sin(pi/4) + sqrt(81)) / (2 * phi)", // Logarithmic and trigonometric functions | ||
"(sqrt(144) * 2 + 5) / (3 * (4 - sin(pi / 6))) + e^2", // Combined square root, trigonometric, and exponential operations | ||
"cos(2 * pi) + tan(pi / 3) * log(32, 2) - sqrt(256)", // Multiple trigonometric and logarithmic functions | ||
"(10 * (3 + 2) - 8 / 2)^2 + 7 * (2^4) - sqrt(225) + phi", // Mixed arithmetic with constants | ||
"(5^2 + 3^3) * (sqrt(81) + sqrt(64)) - tau * log(1000, 10)", // Power and square root with constants | ||
"((8 * sqrt(49) - 2 * e) + log(256, 2) / (2 + cos(pi))) * 1.5", // Nested functions and constants | ||
"(tan(pi / 4) + 5) * (3 + sqrt(36)) / (log(1024, 2) - 4)", // Nested functions with trigonometry and logarithm | ||
"((3 * e + 2 * sqrt(100)) - cos(tau / 4)) * log(27, 3) + phi", // Mixed constant usage and functions | ||
"(sqrt(100) + 5 * sin(pi / 6) - 8 / log(64, 2)) + e^(1.5)", // Complex mix of square root, division, and exponentiation | ||
"((sin(pi/2) + cos(0)) * (e^2 - 2 * sqrt(16))) / (log(100, 10) + pi)", // Nested trigonometric, exponential, and logarithmic functions | ||
"(5 * (7 + sqrt(121)) - (log(243, 3) * phi)) + 3^5 / tau", // | ||
} |
Oops, something went wrong.