7 releases (3 stable)
1.0.2 | Dec 19, 2021 |
---|---|
1.0.1 | Apr 22, 2021 |
0.2.2 | Apr 16, 2021 |
0.1.0 | Apr 2, 2021 |
#133 in Simulation
36KB
1K
SLoC
Dicer
version 1.0.1
About
A simple library for evaluating strings representing dice rolls in rust. Dicer uses an LL(1) grammar and a recursive descent parser to parse strings and simulate randomly rolled dice. See grammar.md for examples of valid strings.
Example
use dicer::eval;
fn main() {
// simple expression
let test = String::from("1d20 + 4 + min([2d4-MAX], 3) {3}");
println!("parse: \"{}\"\n", test);
let result = eval(&test).unwrap();
for res in result {
println!("{} = {}", res.str, res.value);
}
}
output:
parse: "1d20 * (3+2) + min([2d4 - MAX], 3)"
(6) * (3 + 2) + min([ (3 + 1) -3 ], 3) = 31
Dependencies
~310KB