From d96a9c9899690cf639905af8e1006d539f1d49a6 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Tue, 5 Mar 2019 14:18:55 -0500 Subject: improve parsing of infix operators --- src/commands/roll.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/roll.rs b/src/commands/roll.rs index a2a05ef..733fc76 100644 --- a/src/commands/roll.rs +++ b/src/commands/roll.rs @@ -35,7 +35,7 @@ enum CalcParseError { } impl CalcExpr { - fn parse>(input: S) -> Result> { + pub fn parse>(input: S) -> Result> { parse_expr(CompleteStr(input.as_ref())) .map_err(|e| CalcParseError::Nom(format!("{}", e))) .and_then(|(s, res)| { @@ -50,7 +50,7 @@ impl CalcExpr { .map_err(Error::from) } - fn compute(self: Box) -> f64 { + pub fn compute(self: Box) -> f64 { use self::CalcExpr::*; use self::BinOp::*; use self::UnaryOp::*; @@ -138,7 +138,7 @@ fn parse_expr(input: CompleteStr) -> nom::IResult> { fn parse_add_sub_mod(input: CompleteStr) -> nom::IResult> { ws!(input, do_parse!( - tpl: tuple!(up_to_div_mul, ws!(one_of!("+-%")), up_to_div_mul) >> + tpl: tuple!(up_to_div_mul, ws!(one_of!("+-%")), parse_expr) >> ({ let (expr1, op, expr2) = tpl; let op = match op { @@ -154,7 +154,7 @@ fn parse_add_sub_mod(input: CompleteStr) -> nom::IResult nom::IResult> { ws!(input, do_parse!( - tpl: tuple!(up_to_binary_prefix, ws!(one_of!("/*")), up_to_binary_prefix) >> + tpl: tuple!(up_to_binary_prefix, ws!(one_of!("/*")), parse_expr) >> ({ let (expr1, op, expr2) = tpl; let op = match op { -- cgit v1.3.1