#rpg #dice #parser #operation #evaluator

die-sir

A dice expression parser and evaluator

1 unstable release

0.1.0 Mar 14, 2025

#378 in Parser tooling

Download history 133/week @ 2025-03-12 2/week @ 2025-03-19

135 downloads per month

MIT license

17KB
376 lines

DieSir is a library for parsing and evaluating dice expressions as well as basic math expressions.

This crate provides functionality to parse and evaluate dice rolling expressions like "2d6 + 3"


Die-Sir

Die-Sir (Dicer) is a dice parser for random dice rolling with support for modifiers through basic math operations

Usage

Add this to your Cargo.toml:

[dependencies]
die-sir = "0.1.0"

Basic usage example:

use die_sir::evaluate;

fn main() {
    let result = evaluate("2d6 + 3".to_string());
    match result {
        Ok(val) => println!("Result: {}", val),
        Err(e) => println!("Error: {}", e),
    }
}

Features

  • Parse dice expressions (e.g., "2d6", "1d20+5")
  • Support for basic arithmetic operations (+, -, *, /, ^)
  • Error handling for invalid expressions and number overflow

License

This project is licensed under the MIT License - see the LICENSE file for details

Dependencies

~325KB