added decimals

This commit is contained in:
Lilith Schier 2026-08-18 20:28:25 +02:00
parent 8084e34cc0
commit 074c7a10e4
2 changed files with 26 additions and 6 deletions

View file

@ -480,7 +480,7 @@ impl<'a> WitnessSet for DiscordMdWitnessSet<'a> {
type Error = DiscordMdWitnessError;
fn witness_roll(&mut self, dice: DiceRoll) -> Result<Self::Ok, Self::Error> {
if self.parent.dice_written >= 100 {
if self.parent.dice_written >= 50 {
if !self.dice_elided {
write!(self.parent.buffer, "…")?;
self.dice_elided = true;

View file

@ -1,5 +1,10 @@
use crate::dice::{CompareFragment, DiceFormula, Expression::{self, Const}};
use crate::dice::{
CompareFragment, DiceFormula,
Expression::{self, Const},
};
use Assoc::Left;
use nom::character::complete::digit0;
use nom::combinator::recognize;
use nom::{
Parser,
branch::alt,
@ -115,7 +120,10 @@ fn expr<'c, 'i>(
}
fn number(i: &str) -> IResult<&str, Expression> {
map_res(digit1(), |s: &str| s.parse::<f64>())
map_res(
alt((recognize((digit0, tag("."), digit1())), digit1())),
|s: &str| s.parse::<f64>(),
)
.map(Const)
.parse_complete(i)
}
@ -154,6 +162,18 @@ mod test {
assert_matches!(expression, Expression::Dice { .. });
}
#[test]
pub fn parse_decimal() {
let expression = parse("2.5+2.5").unwrap();
assert_matches!(expression, Expression::Add { .. });
}
#[test]
pub fn parse_decimal2() {
let expression = parse(".4*.8").unwrap();
assert_matches!(expression, Expression::Mul { .. });
}
#[test]
pub fn parse_bare_dice() {
let expression = parse("d8").unwrap();