2020-06-22 18:20:11 +00:00
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod lib_test;
|
|
|
|
|
|
|
|
|
|
fn parse_dice_segments<'a>(cmd: &'a str) -> Vec<regex::Captures<'a>> {
|
|
|
|
|
let regex = Regex::new(r#"(?x)
|
2020-06-22 20:13:06 +00:00
|
|
|
(?P<op>[+\-/*])?
|
|
|
|
|
\s*
|
|
|
|
|
(?:
|
|
|
|
|
(?:
|
|
|
|
|
(?P<count>\d+)? # count (optional)
|
|
|
|
|
d
|
|
|
|
|
(?P<size>\d+) # dice size
|
|
|
|
|
(?:d(?P<drop>\d+))?
|
|
|
|
|
) | (?:
|
|
|
|
|
(?P<mod>\d+)
|
|
|
|
|
)
|
|
|
|
|
)
|
2020-06-22 18:20:11 +00:00
|
|
|
"#).expect("Failed to compile regex");
|
|
|
|
|
|
|
|
|
|
regex.captures_iter(cmd).collect()
|
|
|
|
|
}
|