hey it can calculate 4 again xP
This commit is contained in:
		
					parent
					
						
							
								8a44d045ae
							
						
					
				
			
			
				commit
				
					
						fb563addf4
					
				
			
		
					 2 changed files with 28 additions and 9 deletions
				
			
		|  | @ -21,16 +21,9 @@ pub fn parser<'src>() -> impl Parser<'src, &'src [Token<'src>], Expression<'src> | ||||||
|     let eq = just(Token::Equals); |     let eq = just(Token::Equals); | ||||||
| 
 | 
 | ||||||
|     let expr = recursive(|expr| { |     let expr = recursive(|expr| { | ||||||
|         let atom = { |         let atom = select! { | ||||||
|             let parenthesized = expr |             Token::Float(x) => Expression::Float(x), | ||||||
|                 .clone() |  | ||||||
|                 .delimited_by(just(Token::ParenBegin), just(Token::ParenEnd)); |  | ||||||
| 
 | 
 | ||||||
|             let integer = select! { |  | ||||||
|                 Token::Integer(n) => Expression::Integer(n), |  | ||||||
|             }; |  | ||||||
| 
 |  | ||||||
|             parenthesized.or(integer) |  | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         let unary = just(Token::Substract) |         let unary = just(Token::Substract) | ||||||
|  |  | ||||||
|  | @ -1,3 +1,5 @@ | ||||||
|  | use std::fmt; | ||||||
|  | 
 | ||||||
| use logos::{Lexer, Logos}; | use logos::{Lexer, Logos}; | ||||||
| 
 | 
 | ||||||
| #[derive(Logos, Debug, Clone, PartialEq)] | #[derive(Logos, Debug, Clone, PartialEq)] | ||||||
|  | @ -56,3 +58,27 @@ pub enum Token<'src> { | ||||||
|     #[token("else")] |     #[token("else")] | ||||||
|     Keyword(&'src str), |     Keyword(&'src str), | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | impl fmt::Display for Token<'_> { | ||||||
|  |     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||||
|  |         match self { | ||||||
|  |             Token::Float(s) => write!(f, "{s}"), | ||||||
|  |             Token::Add => write!(f, "+"), | ||||||
|  |             Token::Bool(_) => write!(f, "+"), | ||||||
|  |             Token::Substract => write!(f, "-"), | ||||||
|  |             Token::Multiply => write!(f, "*"), | ||||||
|  |             Token::Divide => write!(f, "/"), | ||||||
|  |             Token::Equals => write!(f, "="), | ||||||
|  |             Token::Colon => write!(f, ":"), | ||||||
|  |             Token::ParenBegin => write!(f, "("), | ||||||
|  |             Token::ParenEnd => write!(f, ")"), | ||||||
|  |             Token::BraceBegin => write!(f, "{{"), | ||||||
|  |             Token::BraceEnd => write!(f, "}}"), | ||||||
|  |             Token::Integer(s) => write!(f, "{s}"), | ||||||
|  |             Token::Ident(s) => write!(f, "{s}"), | ||||||
|  |             Token::String(s) => write!(f, "{s}"), | ||||||
|  |             Token::Keyword(s) => write!(f, "{s}"), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue