hey it can calculate 4 again xP

This commit is contained in:
LunarAkai 2025-08-07 01:53:49 +02:00
commit fb563addf4
2 changed files with 28 additions and 9 deletions

View file

@ -21,16 +21,9 @@ pub fn parser<'src>() -> impl Parser<'src, &'src [Token<'src>], Expression<'src>
let eq = just(Token::Equals);
let expr = recursive(|expr| {
let atom = {
let parenthesized = expr
.clone()
.delimited_by(just(Token::ParenBegin), just(Token::ParenEnd));
let atom = select! {
Token::Float(x) => Expression::Float(x),
let integer = select! {
Token::Integer(n) => Expression::Integer(n),
};
parenthesized.or(integer)
};
let unary = just(Token::Substract)

View file

@ -1,3 +1,5 @@
use std::fmt;
use logos::{Lexer, Logos};
#[derive(Logos, Debug, Clone, PartialEq)]
@ -56,3 +58,27 @@ pub enum Token<'src> {
#[token("else")]
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}"),
}
}
}