From 24b221bf428ee46bfc90e186c84fbe5dca18aa7e Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 14 Jun 2023 08:59:06 -0700 Subject: [PATCH] Added "per" division --- TODO.md | 1 - src/evaluate/operator.rs | 1 + src/parser/token/operator.rs | 11 +++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 120fe8b..9920919 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ - Reference previous results - Minimize parenthesis when printing expressions - Sane autoconversion (mi + km) - - "per" as division? - -> as "to" - strip_unit function diff --git a/src/evaluate/operator.rs b/src/evaluate/operator.rs index 3dd7b92..c4e7959 100644 --- a/src/evaluate/operator.rs +++ b/src/evaluate/operator.rs @@ -16,6 +16,7 @@ pub fn eval_operator(op: &Operator, args: &VecDeque) -> Result { panic!() } Operator::Negative => { diff --git a/src/parser/token/operator.rs b/src/parser/token/operator.rs index e55acd0..d43b1c5 100644 --- a/src/parser/token/operator.rs +++ b/src/parser/token/operator.rs @@ -12,6 +12,7 @@ use super::Function; #[repr(usize)] pub enum Operator { ModuloLong = 0, // Mod invoked with "mod" + DivideLong, UnitConvert, Subtract, Add, @@ -69,6 +70,7 @@ impl Operator { "i*" => {Some( Operator::ImplicitMultiply )}, "%" => {Some( Operator::Modulo )}, "mod" => {Some( Operator::ModuloLong )}, + "per" => {Some( Operator::DivideLong )}, "to" => {Some( Operator::UnitConvert )}, "^"|"**" => {Some( Operator::Power )}, "!" => {Some( Operator::Factorial )}, @@ -146,6 +148,7 @@ impl Operator { ) }, + Operator::DivideLong | Operator::Divide => { if args.len() != 2 { panic!() } let a = args.pop_front().unwrap(); @@ -232,6 +235,14 @@ impl Operator { ); }, + Operator::DivideLong => { + return format!( + "{} per {}", + self.add_parens_to_arg(&args[0]), + self.add_parens_to_arg(&args[1]) + ); + }, + Operator::UnitConvert => { return format!( "{} to {}",