A LOT of bug fixes
This commit is contained in:
+14
-24
@@ -11,6 +11,7 @@ pub enum AstType {
|
||||
MutVariableDeceleration,
|
||||
Include,
|
||||
IncludeLocal,
|
||||
CodeBlock,
|
||||
Other
|
||||
}
|
||||
|
||||
@@ -65,13 +66,12 @@ impl Parser {
|
||||
}
|
||||
pub fn next(&mut self) -> Ast {
|
||||
let mut ast_res: Ast = Ast {tokens: vec![], ast_type: AstType::Other};
|
||||
let mut index = self.index as usize;
|
||||
let index = self.index as usize;
|
||||
if index == self.tokens.len() {panic!("Reached the end of tokens")}
|
||||
let token = &self.tokens[index];
|
||||
match token.token_type {
|
||||
TokenType::Identifier => {
|
||||
ast_res.tokens.push(self.tokens[index].clone());
|
||||
self.index += 1;
|
||||
if self.tokens.len()-index > 3 && self.tokens[index+1].token_type==TokenType::Identifier && self.tokens[index+2].token_type==TokenType::Round && self.tokens[index+3].token_type==TokenType::Curly {
|
||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
||||
@@ -81,29 +81,19 @@ impl Parser {
|
||||
} else {
|
||||
ast_res.ast_type = AstType::FunctionDeceleration;
|
||||
}
|
||||
self.index += 3;
|
||||
} else if self.tokens.len()-index > 1 && token.value == "cb" && self.tokens[index+1].token_type == TokenType::Curly {
|
||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
||||
ast_res.ast_type = AstType::CodeBlock;
|
||||
self.index += 1;
|
||||
} else if self.tokens[index+1].token_type==TokenType::Identifier {
|
||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
||||
ast_res.ast_type = AstType::VariableDeceleration;
|
||||
self.index += 1;
|
||||
} else if self.tokens[index+1].value=="mut" && self.tokens[index+2].token_type==TokenType::Identifier {
|
||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
||||
ast_res.ast_type = AstType::MutVariableDeceleration;
|
||||
self.index += 2;
|
||||
} else {
|
||||
loop {
|
||||
if index+1 >= self.tokens.len() {break;}
|
||||
index = self.index as usize; // Update the index
|
||||
let ntk = &self.tokens[index]; // Stands for next token
|
||||
if ntk.value=="," {
|
||||
ast_res.tokens.push(ntk.clone());
|
||||
self.index += 1;
|
||||
} else if ntk.token_type==TokenType::Identifier {
|
||||
ast_res.tokens.push(ntk.clone());
|
||||
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.value=="mut" {
|
||||
ast_res.ast_type = AstType::MutVariableDeceleration;
|
||||
self.index += 1;
|
||||
} else {
|
||||
self.index -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TokenType::Include => {
|
||||
|
||||
Reference in New Issue
Block a user