pull/2/head
Mark 2023-03-24 13:18:56 -07:00
parent 1f9bcccab4
commit 1f98645dd4
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 9 additions and 27 deletions

View File

@ -152,24 +152,7 @@ impl Eval for Token {
} else { panic!(); } } else { panic!(); }
}, },
Token::Root(ref v) => { Token::Factorial(ref _v) => { todo!() },
if v.len() != 2 {panic!()};
let a = &v[0];
let b = &v[1];
if let Token::Number(la, va) = a {
if let Token::Number(lb, vb) = b {
let LineLocation{pos: posa, ..} = *la;
let LineLocation{pos: posb, len: lenb} = lb;
Token::Number(
LineLocation { pos: posa, len: posb - posa + lenb },
va.powf(1f64 / *vb)
)
} else { panic!(); }
} else { panic!(); }
},
Token::Factorial(ref v) => { todo!() },
_ => panic!() _ => panic!()
} }
} }

View File

@ -1,10 +1,9 @@
use std::collections::VecDeque;
use crate::parser::Token; use crate::parser::Token;
use crate::parser::Eval; use crate::parser::Eval;
use crate::parser::LineLocation; use crate::parser::LineLocation;
use crate::parser::ParserError; use crate::parser::ParserError;
#[inline(always)]
fn get_at_coords<'a>(g: &'a mut Token, coords: &Vec<usize>) -> &'a mut Token { fn get_at_coords<'a>(g: &'a mut Token, coords: &Vec<usize>) -> &'a mut Token {
let mut h = &mut *g; let mut h = &mut *g;
@ -69,13 +68,13 @@ pub fn evaluate(
} }
match h { match h {
Token::Multiply(v) | Token::Multiply(_) |
Token::Divide(v) | Token::Divide(_) |
Token::Add(v) | Token::Add(_) |
Token::Factorial(v) | Token::Factorial(_) |
Token::Negative(v) | Token::Negative(_) |
Token::Power(v) | Token::Power(_) |
Token::Modulo(v) Token::Modulo(_)
=> { => {
coords.push(0); coords.push(0);
continue 'outer; continue 'outer;