mirror of
				https://github.com/rm-dr/daisy
				synced 2025-10-30 14:04:47 -07:00 
			
		
		
		
	Added more token methods
This commit is contained in:
		| @ -9,17 +9,7 @@ fn get_at_coords<'a>(g: &'a mut Token, coords: &Vec<usize>) -> &'a mut Token { | ||||
| 	let mut h = &mut *g; | ||||
|  | ||||
| 	for t in coords.iter() { | ||||
| 		let inner = match h { | ||||
| 			Token::Multiply(ref mut v) => v, | ||||
| 			Token::Divide(ref mut v) => v, | ||||
| 			Token::Add(ref mut v) => v, | ||||
| 			Token::Factorial(ref mut v) => v, | ||||
| 			Token::Negative(ref mut v) => v, | ||||
| 			Token::Power(ref mut v) => v, | ||||
| 			Token::Modulo(ref mut v) => v, | ||||
| 			_ => panic!() | ||||
| 		}; | ||||
|  | ||||
| 		let inner = h.get_args().unwrap(); | ||||
| 		h = &mut inner[*t]; | ||||
| 	} | ||||
|  | ||||
| @ -37,17 +27,7 @@ pub fn p_evaluate( | ||||
|  | ||||
| 		let mut h = &mut g; | ||||
| 		for t in coords.iter() { | ||||
| 			let inner: Option<&mut VecDeque<Token>> = match h { | ||||
| 				Token::Multiply(ref mut v) | ||||
| 				| Token::Divide(ref mut v) | ||||
| 				| Token::Add(ref mut v) | ||||
| 				| Token::Factorial(ref mut v) | ||||
| 				| Token::Negative(ref mut v) | ||||
| 				| Token::Power(ref mut v) | ||||
| 				| Token::Modulo(ref mut v) | ||||
| 				=> Some(v), | ||||
| 				_ => None | ||||
| 			}; | ||||
| 			let inner = h.get_args(); | ||||
|  | ||||
| 			if inner.is_none() || *t >= inner.as_ref().unwrap().len() { | ||||
| 				coords.pop(); | ||||
|  | ||||
| @ -5,18 +5,6 @@ use crate::parser::LineLocation; | ||||
| use crate::parser::ParserError; | ||||
| use crate::parser::Operator; | ||||
|  | ||||
| #[inline(always)] | ||||
| fn get_line_location(t: &Token) -> &LineLocation { | ||||
| 	match t { | ||||
| 		Token::PreNumber(l, _) | | ||||
| 		Token::PreWord(l, _) | | ||||
| 		Token::PreOperator(l, _) | | ||||
| 		Token::PreGroup(l, _) | ||||
| 		=> l, | ||||
| 		_ => panic!() | ||||
| 	} | ||||
| } | ||||
|  | ||||
| #[inline(always)] | ||||
| fn select_op(k: Operator, mut new_token_args: VecDeque<Token>) -> Token { | ||||
| 	match k { | ||||
| @ -87,7 +75,7 @@ fn treeify_binary( | ||||
| 			=> { | ||||
| 				// Binary and right-unary operators cannot | ||||
| 				// follow a binary operator. | ||||
| 				let LineLocation { pos: posa, .. } = *get_line_location(&this); | ||||
| 				let LineLocation { pos: posa, .. } = *this.get_line_location(); | ||||
| 				let LineLocation { pos: posb, len: lenb } = *l; | ||||
| 				return Err(( | ||||
| 					LineLocation{pos: posa, len: posb - posa + lenb}, | ||||
| @ -184,7 +172,7 @@ fn treeify_unaryleft( | ||||
| 			=> { | ||||
| 				// Binary and right-unary operators cannot | ||||
| 				// follow a binary operator. | ||||
| 				let LineLocation { pos: posa, .. } = *get_line_location(&this); | ||||
| 				let LineLocation { pos: posa, .. } = *this.get_line_location(); | ||||
| 				let LineLocation { pos: posb, len: lenb } = *l; | ||||
| 				return Err(( | ||||
| 					LineLocation{pos: posa, len: posb - posa + lenb}, | ||||
| @ -273,7 +261,7 @@ fn treeify_unaryright( | ||||
| 			match o { | ||||
| 				// Left unary operators | ||||
| 				Operator::Negative => { | ||||
| 					let LineLocation { pos: posa, .. } = *get_line_location(&this); | ||||
| 					let LineLocation { pos: posa, .. } = *this.get_line_location(); | ||||
| 					let LineLocation { pos: posb, len: lenb } = *l; | ||||
| 					return Err(( | ||||
| 						LineLocation{pos: posa, len: posb - posa + lenb}, | ||||
| @ -284,14 +272,14 @@ fn treeify_unaryright( | ||||
| 			}; | ||||
| 		} else { | ||||
| 			return Err(( | ||||
| 				*get_line_location(&this), | ||||
| 				*this.get_line_location(), | ||||
| 				ParserError::Syntax | ||||
| 			)); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if let Token::PreOperator(l, _) = left { | ||||
| 		let LineLocation { pos: posa, .. } = *get_line_location(&this); | ||||
| 		let LineLocation { pos: posa, .. } = *this.get_line_location(); | ||||
| 		let LineLocation { pos: posb, len: lenb } = *l; | ||||
| 		return Err(( | ||||
| 			LineLocation{pos: posa, len: posb - posa + lenb}, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user