evaluroll

Crates.ioevaluroll
lib.rsevaluroll
version0.1.1
sourcesrc
created_at2023-11-24 21:55:31.729108
updated_at2023-11-24 22:04:49.109514
descriptionA dice expression parser and evaluator.
homepage
repositoryhttps://github.com/zshift/evaluroll/
max_upload_size
id1047825
size33,324
Peter David Faria (zshift)

documentation

README

evaluroll

Evaluroll is a dice roll evaluator for tabletop games. It supports dice notation and basic arithmetic, as specified in the roll20 spec. It also supports keeping and dropping dice, as well as parenthesized expressions.

It also supports parsing into an AST, which can be used to evaluate the expression multiple times.

Examples

Parsing an expression into an AST:

let ast = evaluroll::parse("1d20")?;

Evaluating an AST:

use evaluroll::Eval;

let ast = evaluroll::parse("1d20")?;

let mut rng = rand::thread_rng();
let output = ast.eval(&mut rng)?;

assert_eq!(1, output.rolls.len());
assert!((1..=20).contains(&output.total));

Evaluating an expression directly:

let mut rng = rand::thread_rng();
let output = evaluroll::eval(&mut rng, "1d20")?;

assert_eq!(1, output.rolls.len());
assert!((1..=20).contains(&output.total));

Features

Evaluroll has the following features:

  • trace: Enables tracing of the AST and the output of the parser.

License: MIT

Commit count: 5

cargo fmt