Removed `=` operator

pull/2/head
Mark 2023-08-03 14:02:45 -07:00
parent 07edc4f047
commit 4ddafd84ef
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
4 changed files with 6 additions and 38 deletions

View File

@ -95,15 +95,6 @@ pub fn evaluate(t: &Expression, context: &mut Context, allow_incomplete: bool) -
} else { } else {
// Move down the tree // 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); coords.push(0);
} }
} }

View File

@ -6,24 +6,13 @@ use super::EvalError;
use crate::context::Context; use crate::context::Context;
pub fn eval_operator(g: &Expression, context: &mut Context) -> Result<Option<Expression>, (LineLocation, EvalError)> { pub fn eval_operator(g: &Expression, _context: &mut Context) -> Result<Option<Expression>, (LineLocation, EvalError)> {
let Expression::Operator(op_loc, op, args) = g else {panic!()}; let Expression::Operator(op_loc, op, args) = g else {panic!()};
match op { match op {
Operator::Function(_) => unreachable!("Functions are handled seperately."), 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 => { Operator::Negative => {
if args.len() != 1 { panic!() }; if args.len() != 1 { panic!() };
let args = &args[0]; let args = &args[0];

View File

@ -13,9 +13,7 @@ use super::Function;
pub enum Operator { pub enum Operator {
// When adding operators, don't forget to update help command text. // When adding operators, don't forget to update help command text.
// It isn't automatically generated. // It isn't automatically generated.
ModuloLong = 0, // Mod invoked with "mod"
Define = 0, // Variable and function definition
ModuloLong, // Mod invoked with "mod"
DivideLong, // Division invoked with "per" DivideLong, // Division invoked with "per"
UnitConvert, UnitConvert,
Subtract, Subtract,
@ -69,7 +67,6 @@ impl Operator {
} }
return match s { return match s {
"=" => {Some( Operator::Define )},
"+" => {Some( Operator::Add )}, "+" => {Some( Operator::Add )},
"-" => {Some( Operator::Subtract )}, "-" => {Some( Operator::Subtract )},
"neg" => {Some( Operator::Negative )}, "neg" => {Some( Operator::Negative )},
@ -146,14 +143,6 @@ impl Operator {
pub fn print(&self, args: &VecDeque<Expression>) -> String { pub fn print(&self, args: &VecDeque<Expression>) -> String {
match self { match self {
Operator::Define => {
return format!(
"{} = {}",
self.add_parens_to_arg(&args[0]),
self.add_parens_to_arg(&args[1])
);
},
Operator::Negative => { Operator::Negative => {
return format!("-{}", self.add_parens_to_arg(&args[0])); return format!("-{}", self.add_parens_to_arg(&args[0]));
}, },

View File

@ -68,9 +68,8 @@ pub fn tokenize(input: &String) -> VecDeque<Token> {
for (i, c) in input.chars().enumerate() { for (i, c) in input.chars().enumerate() {
match c { match c {
// Number // Numbers
// Commas act just like dots. '.' | '0'..='9' => {
',' | '.' | '0'..='9' => {
match &mut t { match &mut t {
// If we're already building a number, // If we're already building a number,
// append. // append.
@ -137,10 +136,10 @@ pub fn tokenize(input: &String) -> VecDeque<Token> {
}, },
// Operator // Operator
'^'|'!'|'%'|'\\'|
'*'|'×'|'/'|'÷'| '*'|'×'|'/'|'÷'|
'^'|'!'|'%'|'='|
'>'|'<'|'?'|'@'| '>'|'<'|'?'|'@'|
'&'|'|'|'~'|'\\' '&'|'|'|'~'
=> { => {
match &mut t { match &mut t {
Some(Token::Operator(_, val)) => { val.push(c); }, Some(Token::Operator(_, val)) => { val.push(c); },