mut declerations

This commit is contained in:
2024-04-08 15:44:33 +02:00
parent bc5fa1bd89
commit de2889c5d8
2 changed files with 8 additions and 9 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ mod parser;
use parser::Parser;
fn main() {
let input = "int mut x";
let input = "int<x> mut x";
println!("\n\n\n\n");
let tokens = lex(input, false);
let mut ast = Parser::new(tokens.clone());
+7 -8
View File
@@ -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;