diff --git a/src/dice.rs b/src/dice.rs index 522f3f6..12f51bf 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -480,7 +480,7 @@ impl<'a> WitnessSet for DiscordMdWitnessSet<'a> { type Error = DiscordMdWitnessError; fn witness_roll(&mut self, dice: DiceRoll) -> Result { - if self.parent.dice_written >= 100 { + if self.parent.dice_written >= 50 { if !self.dice_elided { write!(self.parent.buffer, "…")?; self.dice_elided = true; diff --git a/src/parsing.rs b/src/parsing.rs index 1a74101..329ce5b 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -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,9 +120,12 @@ fn expr<'c, 'i>( } fn number(i: &str) -> IResult<&str, Expression> { - map_res(digit1(), |s: &str| s.parse::()) - .map(Const) - .parse_complete(i) + map_res( + alt((recognize((digit0, tag("."), digit1())), digit1())), + |s: &str| s.parse::(), + ) + .map(Const) + .parse_complete(i) } fn basic_operand<'c, 'i>( @@ -128,7 +136,7 @@ fn basic_operand<'c, 'i>( fn compare_fragment<'c, 'i>( ctx: &'c Context, -) -> impl Parser<&'i str, Output = CompareFragment, Error = InternalError<&'i str>> + use<'c, 'i> { +) -> impl Parser<&'i str, Output = CompareFragment, Error = InternalError<&'i str>> + use<'c, 'i> { use CompareFragment::*; alt(( preceded(tag("="), basic_operand(ctx)).map(|x| Eq(Box::new(x))), @@ -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();