Expand description
Example:
use expr::{Context, Parser};
let mut p = Parser::new();
let mut ctx = Context::default();
ctx.insert("two".to_string(), 2);
let three: i64 = p.eval("1 + two", &ctx).unwrap().as_number().unwrap();
assert_eq!(three, 3);
p.add_function("add", |c| {
let mut sum = 0;
for arg in c.args {
sum += arg.as_number().unwrap();
}
Ok(sum.into())
});
let six: i64 = p.eval("add(1, two, 3)", &ctx).unwrap().as_number().unwrap();
assert_eq!(six, 6);
Macros§
Structs§
- Context
- Environment
- Struct containing custom environment setup for expr evaluation (e.g. custom function definitions)
- Parser
Deprecated - Main struct for parsing and evaluating expr programs
- Program
- A parsed expr program that can be run
Enums§
- Error
- An error that can occur when parsing or evaluating an expr program
- Rule
- Value
- Represents a data value as input or output to an expr program
Functions§
- compile
- Parse an expr program to be run later
- eval
- Compile and run an expr program in one step, using the default environment.
- run
- Run a compiled expr program, using the default environment