Skip to main content

parse_roll_exprs

Function parse_roll_exprs 

Source
pub fn parse_roll_exprs(tokens: &[&str]) -> Result<ParsedRoll>
Expand description

Parses dice expressions and integer modifiers.

Dice expressions use an optional positive count followed by a die name: d6, 3d6, D20, or 2Coin. Bare integers are returned as modifiers.

§Errors

Returns DiceError::InvalidArguments when tokens is empty and DiceError::InvalidExpression when a token cannot be interpreted as a die expression or integer modifier.

§Examples

use rdice_core::parse_roll_exprs;

let parsed = parse_roll_exprs(&["3d6", "Coin", "-2"])?;

assert_eq!(parsed.dice, vec!["d6", "d6", "d6", "Coin"]);
assert_eq!(parsed.modifiers, vec![-2]);