lexper 0.0.2

A simple CLI calculator with a handwritten lexer and parser in Rust.
Documentation
  • Coverage
  • 28%
    14 out of 50 items documented3 out of 8 items with examples
  • Size
  • Source code size: 27.02 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.48 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • JerryImMouse/lexper
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • JerryImMouse

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(currently sin() and PI as constant).

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
  • Lack of builtin functions and ability to add them yourself. It will be implemented in future updates