From 4ddafd84ef731d968835d1f51a27a83dd77aae1e Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 3 Aug 2023 14:02:45 -0700 Subject: [PATCH] Removed `=` operator --- src/evaluate/evaluate.rs | 9 --------- src/evaluate/operator.rs | 13 +------------ src/parser/expression/operator.rs | 13 +------------ src/parser/stage/tokenize.rs | 9 ++++----- 4 files changed, 6 insertions(+), 38 deletions(-) diff --git a/src/evaluate/evaluate.rs b/src/evaluate/evaluate.rs index d18ee3b..6199654 100644 --- a/src/evaluate/evaluate.rs +++ b/src/evaluate/evaluate.rs @@ -95,15 +95,6 @@ pub fn evaluate(t: &Expression, context: &mut Context, allow_incomplete: bool) - } else { // Move down the tree - - // Don't evaluate the first argument of a define. - // This prevents variables from being expanded before a re-assignment. - if let Expression::Operator(_, Operator::Define, _) = g { - *coords.last_mut().unwrap() += 1; - coords.push(0); - continue; - } - coords.push(0); } } diff --git a/src/evaluate/operator.rs b/src/evaluate/operator.rs index 84aaafe..702df7d 100644 --- a/src/evaluate/operator.rs +++ b/src/evaluate/operator.rs @@ -6,24 +6,13 @@ use super::EvalError; use crate::context::Context; -pub fn eval_operator(g: &Expression, context: &mut Context) -> Result, (LineLocation, EvalError)> { +pub fn eval_operator(g: &Expression, _context: &mut Context) -> Result, (LineLocation, EvalError)> { let Expression::Operator(op_loc, op, args) = g else {panic!()}; match op { Operator::Function(_) => unreachable!("Functions are handled seperately."), - Operator::Define => { - if args.len() != 2 { panic!() }; - let b = &args[1]; - - if let Expression::Variable(l, s) = &args[0] { - let r = context.push_var(s.clone(), b.clone()); - if r.is_err() { return Err((*l, EvalError::BadDefineName)); } - return Ok(Some(b.clone())); - } else { return Err((args[0].get_linelocation(), EvalError::BadDefineName)); } - }, - Operator::Negative => { if args.len() != 1 { panic!() }; let args = &args[0]; diff --git a/src/parser/expression/operator.rs b/src/parser/expression/operator.rs index 9794b1d..a53d006 100644 --- a/src/parser/expression/operator.rs +++ b/src/parser/expression/operator.rs @@ -13,9 +13,7 @@ use super::Function; pub enum Operator { // When adding operators, don't forget to update help command text. // It isn't automatically generated. - - Define = 0, // Variable and function definition - ModuloLong, // Mod invoked with "mod" + ModuloLong = 0, // Mod invoked with "mod" DivideLong, // Division invoked with "per" UnitConvert, Subtract, @@ -69,7 +67,6 @@ impl Operator { } return match s { - "=" => {Some( Operator::Define )}, "+" => {Some( Operator::Add )}, "-" => {Some( Operator::Subtract )}, "neg" => {Some( Operator::Negative )}, @@ -146,14 +143,6 @@ impl Operator { pub fn print(&self, args: &VecDeque) -> String { match self { - Operator::Define => { - return format!( - "{} = {}", - self.add_parens_to_arg(&args[0]), - self.add_parens_to_arg(&args[1]) - ); - }, - Operator::Negative => { return format!("-{}", self.add_parens_to_arg(&args[0])); }, diff --git a/src/parser/stage/tokenize.rs b/src/parser/stage/tokenize.rs index f2b4b9c..aeccfed 100644 --- a/src/parser/stage/tokenize.rs +++ b/src/parser/stage/tokenize.rs @@ -68,9 +68,8 @@ pub fn tokenize(input: &String) -> VecDeque { for (i, c) in input.chars().enumerate() { match c { - // Number - // Commas act just like dots. - ',' | '.' | '0'..='9' => { + // Numbers + '.' | '0'..='9' => { match &mut t { // If we're already building a number, // append. @@ -137,10 +136,10 @@ pub fn tokenize(input: &String) -> VecDeque { }, // Operator + '^'|'!'|'%'|'\\'| '*'|'×'|'/'|'÷'| - '^'|'!'|'%'|'='| '>'|'<'|'?'|'@'| - '&'|'|'|'~'|'\\' + '&'|'|'|'~' => { match &mut t { Some(Token::Operator(_, val)) => { val.push(c); },