{"id":20170583,"url":"https://github.com/yds12/mexe","last_synced_at":"2025-04-10T02:27:23.645Z","repository":{"id":57638374,"uuid":"450798605","full_name":"yds12/mexe","owner":"yds12","description":"Simple and fast arithmetic expression parser","archived":false,"fork":false,"pushed_at":"2023-08-20T15:33:52.000Z","size":38,"stargazers_count":8,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T03:53:22.048Z","etag":null,"topics":["arithmetic","eval","evaluator","expression-evaluator","parser"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yds12.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-22T11:32:29.000Z","updated_at":"2024-08-05T21:48:22.000Z","dependencies_parsed_at":"2023-01-22T17:15:54.725Z","dependency_job_id":null,"html_url":"https://github.com/yds12/mexe","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yds12%2Fmexe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yds12%2Fmexe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yds12%2Fmexe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yds12%2Fmexe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yds12","download_url":"https://codeload.github.com/yds12/mexe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143831,"owners_count":21054835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arithmetic","eval","evaluator","expression-evaluator","parser"],"created_at":"2024-11-14T01:19:44.781Z","updated_at":"2025-04-10T02:27:23.615Z","avatar_url":"https://github.com/yds12.png","language":"Rust","readme":"![loc](https://sloc.xyz/github/yds12/mexe)\n![tests](https://github.com/yds12/mexe/actions/workflows/unit.yml/badge.svg)\n\n**m**athematical **ex**pression **e**valuator.\n\n## How to Use\n\n```rust\nuse mexe::eval;\n\nfn main() {\n    let forty_six = eval(\"(5 * 8) + 6\").unwrap();\n    let two = eval(\"1 + 1\").unwrap();\n    println!(\"{} \u0026 {}\", forty_six, two);\n\n    assert_eq!(forty_six, 46.0);\n    assert_eq!(two, 2.0);\n}\n```\n\nNote: the above `assert_eq`s work, but for float comparison in general use a\ncrate such as `float-cmp`.\n\n## Why?\n\nIf you need to evaluate simple arithmetic expressions, this crate offers a fast\nand lightweight solution.\n\nIn our [current benchmarks](https://github.com/yds12/mexe/actions/workflows/bench.yml),\nit's about 4-10x faster than `meval`, about 2x faster than `fasteval`, and\nthe fully-featured `evalexpr` is generally the slowest. Note that those crates\ndo much more than `mexe` -- especially `evalexpr`. Our focus on a very small\nproblem makes it easier for us to ship a fast and lean library.\n\n## Includes\n\n- sum\n- subtraction\n- multiplication\n- division\n- integers\n- floats\n- parentheses\n- arbitrary whitespace\n\nFloats are represented as `X.Y` where `X` and `Y` are non-empty sequences of\ndigits. The notation with exponents for floats or omitting either side of the\npoint is not accepted.\n\n## Goals\n\n- Minimal\n- Fast: O(n)\n- No dependencies\n- Minimal allocations\n- Thoroughly tested\n\n## Run Tests and Benchmarks\n\nUnit tests and integration tests:\n\n    cargo test\n\nWe leverage the [`glc` crate](https://crates.io/crates/glc) to generate valid\nrandom inputs for `mexe`. The command below will run an ignored integration test\nthat runs indefinitely and shows the output in the terminal until you stop it\nwith `CTRL+C`:\n\n    cargo test --test integration without_bounds -- --nocapture --ignored\n\nBenchmarks:\n\n    cargo bench -- bench_cmp   # comparison with other crates\n    cargo bench -- bench_mexe  # only mexe\n\n### Running the fuzzer\n\nFuzz tests have been ran with [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz).\n\nTo run it yourself, you need to install the nightly toolchain\n(`rustup toolchain install nightly`) and the tool itself:\n`cargo install cargo-fuzz` (check for more detailed instructions and\ndependencies in the project's readme).\n\nAfter that run:\n\n    cargo fuzz init\n    cargo fuzz add fn_eval\n\nGo to `fuzz/fuzz_targets/fn_eval.rs` and paste this code:\n\n```rust\n#![no_main]\nuse libfuzzer_sys::fuzz_target;\n\nfuzz_target!(|data: \u0026[u8]| {\n    // fuzzed code goes here\n    if let Ok(text) = std::str::from_utf8(data) {\n        let _ = mexe::eval(text);\n    }\n});\n```\n\nNow finally run:\n\n    cargo +nightly fuzz run fn_eval\n\n## Grammar\n\n    E  -\u003e T E'\n    E' -\u003e + T E'\n    E' -\u003e - T E'\n    E' -\u003e ε\n    T  -\u003e F T'\n    T' -\u003e * F T'\n    T' -\u003e / F T'\n    T' -\u003e ε\n    F  -\u003e ( E )\n    F  -\u003e n\n    F  -\u003e - ( E )\n    F  -\u003e - n\n\nwhere `ε` is the empty string and `n` is a terminal number token. Grammar idea\nadapted from [this post](https://stackoverflow.com/a/23845375).\n\nOur first implementation uses an LL(1) parser.\n\n## Similar Projects\n\n- [evalexpr](https://crates.io/crates/evalexpr)\n- [meval](https://crates.io/crates/meval)\n- [fasteval](https://crates.io/crates/fasteval)\n- [pmalmgren/rust-calculator](https://github.com/pmalmgren/rust-calculator)\n- [adriaN/simple_rust_parser](https://github.com/adrianN/simple_rust_parser)\n\n## Links\n\n* Documentation: [docs.rs](https://docs.rs/mexe/latest)\n* Crate: [crates.io](https://crates.io/crates/mexe) and [lib.rs](https://lib.rs/crates/mexe)\n* Repository: [Github](https://github.com/yds12/mexe)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyds12%2Fmexe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyds12%2Fmexe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyds12%2Fmexe/lists"}