added decimals
This commit is contained in:
parent
8084e34cc0
commit
074c7a10e4
2 changed files with 26 additions and 6 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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::<f64>())
|
||||
.map(Const)
|
||||
.parse_complete(i)
|
||||
map_res(
|
||||
alt((recognize((digit0, tag("."), digit1())), digit1())),
|
||||
|s: &str| s.parse::<f64>(),
|
||||
)
|
||||
.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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue