aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/parser.rs
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2025-09-12 18:11:33 +0800
committer简律纯 <i@jyunko.cn>2025-09-12 18:11:33 +0800
commit899ca820e34b1b62190e88da71cf734295974a19 (patch)
tree2164917914cb8871d59d78db6305fcc5d14cd99a /src/parser.rs
parent183e39d9ebfe6e48e5ce666dee36b5347d47f53e (diff)
downloadOneRoll-899ca820e34b1b62190e88da71cf734295974a19.tar.gz
OneRoll-899ca820e34b1b62190e88da71cf734295974a19.zip
feat: enhance dice modifiers with new options for aliasing, sorting, and counting
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/parser.rs b/src/parser.rs
index a1800a2..50231c0 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -110,6 +110,12 @@ impl DiceParser {
let inner = pair.into_inner().next().unwrap();
match inner.as_rule() {
Rule::explode => Ok(DiceModifier::Explode),
+ Rule::explode_alias => Ok(DiceModifier::ExplodeAlias),
+ Rule::explode_keep_high => {
+ let num = inner.into_inner().next().unwrap().as_str().parse::<i32>()
+ .map_err(|_| DiceError::ParseError("无效的ExplodeKeepHigh数值".to_string()))?;
+ Ok(DiceModifier::ExplodeKeepHigh(num))
+ }
Rule::reroll => {
let num = inner.into_inner().next().unwrap().as_str().parse::<i32>()
.map_err(|_| DiceError::ParseError("无效的重投数值".to_string()))?;
@@ -120,6 +126,11 @@ impl DiceParser {
.map_err(|_| DiceError::ParseError("无效的条件重投数值".to_string()))?;
Ok(DiceModifier::RerollOnce(num))
}
+ Rule::keep_alias => {
+ let num = inner.into_inner().next().unwrap().as_str().parse::<i32>()
+ .map_err(|_| DiceError::ParseError("无效的取高数值".to_string()))?;
+ Ok(DiceModifier::KeepAlias(num))
+ }
Rule::keep_high => {
let num = inner.into_inner().next().unwrap().as_str().parse::<i32>()
.map_err(|_| DiceError::ParseError("无效的取高数值".to_string()))?;
@@ -140,8 +151,12 @@ impl DiceParser {
.map_err(|_| DiceError::ParseError("无效的丢弃低数值".to_string()))?;
Ok(DiceModifier::DropLow(num))
}
- Rule::unique => {
- Ok(DiceModifier::Unique)
+ Rule::unique => Ok(DiceModifier::Unique),
+ Rule::sort => Ok(DiceModifier::Sort),
+ Rule::count => {
+ let num = inner.into_inner().next().unwrap().as_str().parse::<i32>()
+ .map_err(|_| DiceError::ParseError("无效的计数数值".to_string()))?;
+ Ok(DiceModifier::Count(num))
}
_ => Err(DiceError::ParseError("未知的修饰符".to_string())),
}