diff options
| author | Nathan Perry <avaglir@gmail.com> | 2019-03-05 14:18:55 -0500 |
|---|---|---|
| committer | Nathan Perry <avaglir@gmail.com> | 2019-03-05 14:18:55 -0500 |
| commit | d96a9c9899690cf639905af8e1006d539f1d49a6 (patch) | |
| tree | 39536c849cd514b033570c252a5becc8a828b357 | |
| parent | fc1fcbad504617053d6e8cb63b5eba2f051ec665 (diff) | |
improve parsing of infix operators
| -rw-r--r-- | src/commands/roll.rs | 8 |
1 files 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<S: AsRef<str>>(input: S) -> Result<Box<Self>> { + pub fn parse<S: AsRef<str>>(input: S) -> Result<Box<Self>> { 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<Self>) -> f64 { + pub fn compute(self: Box<Self>) -> f64 { use self::CalcExpr::*; use self::BinOp::*; use self::UnaryOp::*; @@ -138,7 +138,7 @@ fn parse_expr(input: CompleteStr) -> nom::IResult<CompleteStr, Box<CalcExpr>> { fn parse_add_sub_mod(input: CompleteStr) -> nom::IResult<CompleteStr, Box<CalcExpr>> { 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<CompleteStr, Box<CalcEx fn parse_div_mul(input: CompleteStr) -> nom::IResult<CompleteStr, Box<CalcExpr>> { 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 { |
