fixed repeaded AstDef Bug

This commit is contained in:
2024-04-03 18:42:13 +02:00
parent 0907372c1e
commit 5eb7361a4a
+2 -3
View File
@@ -37,7 +37,7 @@ pub fn parse(tokens: &mut Vec<Token>) -> Box<Vec<Ast>> {
let ast_def: Vec<PNode> = vec![ let ast_def: Vec<PNode> = vec![
PNode { PNode {
ast_type: AstTypes::FunctionDecleration, ast_type: AstTypes::FunctionDecleration,
ast_match: vec![AstDef::Optional(TokenType::Identifier)] ast_match: vec![AstDef::NormalValue(TokenType::Identifier, vec!["if".to_string()]), AstDef::Repeated(vec![TokenType::Operator, TokenType::Identifier, ])]
}, },
PNode { PNode {
ast_type: AstTypes::Other, ast_type: AstTypes::Other,
@@ -83,11 +83,10 @@ pub fn parse(tokens: &mut Vec<Token>) -> Box<Vec<Ast>> {
if node_ == tokens[i].token_type { if node_ == tokens[i].token_type {
matched.push(tokens[i].clone()); matched.push(tokens[i].clone());
node_match = true; node_match = true;
i+=1; tokens.drain(0..1);
} }
} }
if node_match { if node_match {
tokens.drain(0..i);
is_match = true; is_match = true;
} else { } else {
break; break;