KevinGimbel / ndice

They see me rollin', they hatin'
MIT License
3 stars 0 forks source link

Modifier values #2

Closed KevinGimbel closed 1 year ago

KevinGimbel commented 1 year ago

+ or - values to be added to a result.

Example:

$ ndice 3d6 +3
$ ndice 1d4 -1
KevinGimbel commented 1 year ago

Needs adjustments to the regex: https://github.com/KevinGimbel/ndice/blob/main/src/lib.rs#L7

const DICE_REGEX: &str = r#"(?P<numberOfDice>[^[dw\s]]+\d?)(?P<diceIndicator>[dw])?(?P<numberOfSides>\d+)"#;

Right now it produces an error:

$ ndice 1w6 +3
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }', /Users/kevin/.cargo/registry/src/github.com-1ecc6299db9ec823/ndice-0.1.0/src/main.rs:25:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This error should be handled as well.

KevinGimbel commented 1 year ago

New regex:

(?P<numberOfDice>[^[dwe\s+-]]+\d?)(?P<explodingDice>[e])?(?P<diceIndicator>[dw])(?P<numberOfSides>\d+)(?P<mod>[+-]\d+)?

Changes to groups:

KevinGimbel commented 1 year ago

Implemented!

Todo: