| Crates.io | dicer |
| lib.rs | dicer |
| version | 1.0.2 |
| created_at | 2021-04-02 22:16:45.525574+00 |
| updated_at | 2021-12-19 15:29:08.388625+00 |
| description | Dice Roller |
| homepage | https://github.com/gnullByte/dicer |
| repository | https://github.com/gnullByte/dicer |
| max_upload_size | |
| id | 377887 |
| size | 42,502 |
version 1.0.1
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.
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