Skip to content

CasualX/pupil-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pupil

MIT License crates.io docs.rs Build status

Arithmetic expression evaluator written in Rust.

It implements a butchered Shunting-yard algorithm.

Pupil

To build the pupil executable, run cargo build. Append the --release switch as needed for optimized builds.

It has three different use cases:

  • Interactive mode.

    Enter expressions and press enter to evaluate them.

    PATH/TO/CRATE/ROOT> cargo run
    Welcome to pupil, the arithmetic expression evaluator.
    
    Enter an expression, eg. 2 + 3, and press enter.
    Press ctrl-C to exit.
    
    >>> 2 + 3
    5
    >>> ^C
    
  • Provide the expression to evaluate as command line arguments.

    This allows to evaluate a single expression and then exit.

    PATH/TO/CRATE/ROOT> cargo run -- 2 + 3
    Welcome to pupil, the arithmetic expression evaluator.
    Ok: 5
    
  • Pipe input.

    Evaluates every line as separate expressions and prints the result line by line.

    PATH/TO/CRATE/ROOT> echo 2 + 3 | cargo run
    5
    

Library

This library can be found on crates.io.

In your Cargo.toml put:

[dependencies]
pupil = "0.2"

A practical example can be found in src/bin/pupil.rs.

Documentation can be found on docs.rs.

Usage

Simple usage:

// Create a basic environment with the default builtins
let mut env = pupil::BasicEnv::default();

// Evaluate expressions in this environment
let result = pupil::eval(&env, "2 + 3");
assert_eq!(result, Ok(5.0));

License

Licensed under MIT License, see license.txt.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.

About

Arithmetic expression evaluator in Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages