Closed KevinGimbel closed 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.
New regex:
(?P<numberOfDice>[^[dwe\s+-]]+\d?)(?P<explodingDice>[e])?(?P<diceIndicator>[dw])(?P<numberOfSides>\d+)(?P<mod>[+-]\d+)?
Changes to groups:
(?P<numberOfDice>[^[dwe\s+-]]+\d?)
: removed ?
as this group isn't optional(?P<explodingDice>[e])?
add exploding dice modifier (optional)(?P<diceIndicator>[dw])
: remove ?
as this group isn't optional(?P<numberOfSides>\d+)
: removed ?
as this group isn't optional(?P<mod>[+-]\d+)?
: add modifier group to add +/- to dice role result Implemented!
Todo:
+
or-
values to be added to a result.Example: