lexper

Crates.iolexper
lib.rslexper
version0.0.3
created_at2025-06-27 23:04:44.355076+00
updated_at2025-07-02 14:52:19.158854+00
descriptionA simple CLI calculator with a handwritten lexer and parser in Rust.
homepagehttps://github.com/JerryImMouse/lexper
repositoryhttps://github.com/JerryImMouse/lexper
max_upload_size
id1729365
size28,391
Jerry (JerryImMouse)

documentation

https://docs.rs/lexper

README

lexper

Crates.io Docs.rs
lexper is a small & lightweight calculator written in Rust with custom lexer and parser.
It also supports constants and function calls.

Installation

Just use cargo add lexper or add the following line to your Cargo.toml:

[dependencies]
lexper = "*" # use the latest version or "*" for the latest

Usage

lexper can be used by 3 ways.

  • Manually creating Lexer, Parser and Context objects and then passing data through them
  • Using lexper::eval(), same as above, just less boilerplate
  • Using lexper::eval!, same as above, but with an ability to format input with {} + 2

Here is the most simple one, the last.

use lexper;

fn main() {
    let result = lexper::eval!("{} + 2", 5).unwrap();
    println!("{}", result);
}

Known Issues

  • Some expressions like "(2 + 2" will work, though the left parenthesis isn't closed, i'll fix that in time.
  • There are no factorial support, it'll be added in future updates
Commit count: 0

cargo fmt