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;
|
type Error = DiscordMdWitnessError;
|
||||||
|
|
||||||
fn witness_roll(&mut self, dice: DiceRoll) -> Result<Self::Ok, Self::Error> {
|
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 {
|
if !self.dice_elided {
|
||||||
write!(self.parent.buffer, "…")?;
|
write!(self.parent.buffer, "…")?;
|
||||||
self.dice_elided = true;
|
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 Assoc::Left;
|
||||||
|
use nom::character::complete::digit0;
|
||||||
|
use nom::combinator::recognize;
|
||||||
use nom::{
|
use nom::{
|
||||||
Parser,
|
Parser,
|
||||||
branch::alt,
|
branch::alt,
|
||||||
|
|
@ -115,7 +120,10 @@ fn expr<'c, 'i>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn number(i: &str) -> IResult<&str, Expression> {
|
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)
|
.map(Const)
|
||||||
.parse_complete(i)
|
.parse_complete(i)
|
||||||
}
|
}
|
||||||
|
|
@ -154,6 +162,18 @@ mod test {
|
||||||
assert_matches!(expression, Expression::Dice { .. });
|
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]
|
#[test]
|
||||||
pub fn parse_bare_dice() {
|
pub fn parse_bare_dice() {
|
||||||
let expression = parse("d8").unwrap();
|
let expression = parse("d8").unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue