From de2889c5d8259861f75f92d9bd5f2cd7c5767a00 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Mon, 8 Apr 2024 15:44:33 +0200 Subject: [PATCH] mut declerations --- src/main.rs | 2 +- src/parser.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5c09e11..174b359 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod parser; use parser::Parser; fn main() { - let input = "int mut x"; + let input = "int mut x"; println!("\n\n\n\n"); let tokens = lex(input, false); let mut ast = Parser::new(tokens.clone()); diff --git a/src/parser.rs b/src/parser.rs index 9aac16b..e249a56 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,10 +1,11 @@ use crate::lexer::{Token, TokenType}; use std::fmt; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum AstType { FunctionDeceleration, VariableDeceleration, + MutVariableDeceleration, Other } @@ -75,14 +76,12 @@ impl Parser { self.index += 1; } else if ntk.token_type==TokenType::Identifier { ast_res.tokens.push(ntk.clone()); - ast_res.ast_type = AstType::VariableDeceleration; + if ast_res.ast_type != AstType::VariableDeceleration && ast_res.ast_type != AstType::MutVariableDeceleration { + ast_res.ast_type = AstType::VariableDeceleration; + } self.index += 1; - } else if ntk.token_type==TokenType::Keyword { - ast_res.tokens.push(ntk.clone()); - ast_res.ast_type = AstType::VariableDeceleration; - self.index += 1; - } else if ntk.token_type==TokenType::Angle { - ast_res.tokens.push(ntk.clone()); + } else if ntk.value=="mut" { + ast_res.ast_type = AstType::MutVariableDeceleration; self.index += 1; } else { self.index -= 1;