This commit is contained in:
2024-04-02 23:54:40 +02:00
parent 55fe45717c
commit 65c9856762
3 changed files with 23 additions and 10 deletions
+14 -2
View File
@@ -4,7 +4,8 @@ use std::fmt;
#[derive(Debug, Clone)]
pub enum AstTypes {
FunctionDecleration
FunctionDecleration,
Other
}
pub struct Ast {
@@ -22,7 +23,8 @@ impl<'a> fmt::Debug for Ast {
pub enum AstDef {
Normal(TokenType),
Repeated(TokenType),
Optional(TokenType)
Optional(TokenType),
Else
}
pub struct PNode {
@@ -40,6 +42,10 @@ pub fn parse(tokens: &mut Vec<Token>) -> Box<Vec<Ast>> {
ast_type: AstTypes::FunctionDecleration,
ast_match: vec![AstDef::Normal(TokenType::Keyword)]
},
PNode {
ast_type: AstTypes::Other,
ast_match: vec![AstDef::Else]
},
];
let tokens_len = tokens.len();
let mut ast: Vec<Ast> = Vec::new();
@@ -62,8 +68,14 @@ pub fn parse(tokens: &mut Vec<Token>) -> Box<Vec<Ast>> {
is_match = true;
} else {
is_match = false;
break;
}
}
AstDef::Else => {
matched.push(tokens[i].clone());
tokens.drain(0..1);
is_match = true;
}
_ => {}
}
}