Crate pupil [] [src]

Arithmetic expression evaluator.

Start things off by creating its environment which will hold the available builtins and the last answer.

extern crate pupil;
 
 // Creates an empty environment.
 let empty = pupil::Env::new();
 // Creates an environment initialized with the default builtins.
 let env = pupil::Env::default();

Create an expression and bind it to its environment.

 let mut expr = pupil::Expr::new(&env);
 
 // Feed it input, note that you cannot give it partial tokens.
 expr.feed("2 +").unwrap();
 expr.feed("3").unwrap();
 
 // Calculate the final result.
 let result = expr.result().unwrap();

You can perform the expression evaluation in a single step.

 let result = pupil::Expr::new(&env).eval("2 + 3").unwrap();

Reexports

pub use expr::Expr;
pub use env::Env;

Modules

builtins

Builtins.

env

Environment.

expr

Expressions.

lexer

Lexing.

op

Operators.