#calculator #expressions #parser #calc #name #evaluating

bin+lib calculate

Rust library for parsing and processing arithmetic expressions

8 releases (4 breaking)

Uses old Rust 2015

0.5.1 Nov 13, 2017
0.5.0 Oct 26, 2017
0.4.1 Oct 26, 2017
0.3.0 Jul 21, 2017
0.1.0 Jul 6, 2017

#2112 in Parser implementations

34 downloads per month
Used in ion-shell

Custom license

52KB
1.5K SLoC

calc

Build Status

calc is a Rust library for tokenizing and evaluating arithmetic expressions with a command line application of the same name included.

NOTE: The name of the project, binary, and library are calc but the package name is calculate. This will remain depending on if this project can acquire the calc crate which is currently being squatted on.

Usage

As a Library

Add calc as a dependency in your Cargo.toml:

[dependencies]
calculate = "0.5.*"

Then make use of the library functions:

extern crate calc;

use calc::eval;
use std::io::{self, BufRead, stdout, stdin, Write};

fn main() {
    let stdout = stdout();
    let mut stdout = stdout.lock();
    let stdin = stdin();
    for line in stdin.lock().lines() {
        match line.unwrap().trim() {
            "" => (),
            "exit" => break,
            s => writeln!(stdout, "{}", eval(s)).unwrap(),
        }
    }
}

As an Executable

$ cargo install calculate
...
$ calc

Dependencies

~2–2.7MB
~44K SLoC