This commit is contained in:
2024-05-10 15:06:17 +02:00
parent a7f085fb07
commit 7aae829763
4 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ const SYNTAX: [Node; 14] = [
}, },
Node { Node {
token_type: TokenType::Operator, token_type: TokenType::Operator,
token_regex: Lazy::new(|| Regex::new(r"^[|\-|\+|\*|\=|\!]").unwrap()) token_regex: Lazy::new(|| Regex::new(r"^[|\-|\+|\*|\=|\!|\&]").unwrap())
}, },
Node { Node {
token_type: TokenType::Round, token_type: TokenType::Round,
+5
View File
@@ -8,6 +8,7 @@ pub enum AstType {
FunctionDeceleration, FunctionDeceleration,
VoidFunctionDeceleration, VoidFunctionDeceleration,
VariableDeceleration, VariableDeceleration,
PointerDeceleration,
MutVariableDeceleration, MutVariableDeceleration,
Include, Include,
IncludeLocal, IncludeLocal,
@@ -95,6 +96,10 @@ impl Parser {
ast_res.tokens.push(self.tokens[index+2].clone()); ast_res.tokens.push(self.tokens[index+2].clone());
ast_res.ast_type = AstType::MutVariableDeceleration; ast_res.ast_type = AstType::MutVariableDeceleration;
self.index += 2; self.index += 2;
} else if self.tokens[index+1].value=="*" && self.tokens[index+2].token_type==TokenType::Identifier {
ast_res.tokens.push(self.tokens[index+2].clone());
ast_res.ast_type = AstType::PointerDeceleration;
self.index += 2;
} }
} }
} }
+4 -1
View File
@@ -125,6 +125,8 @@ pub fn transpile_round(input: String, state: LexerState) -> String {
result += format!("{}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str(); result += format!("{}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
} else if ast.ast_type == AstType::MutVariableDeceleration { } else if ast.ast_type == AstType::MutVariableDeceleration {
result += format!("mut {}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str(); result += format!("mut {}: {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
} else if ast.ast_type == AstType::PointerDeceleration {
result += format!("{}: &mut {}", ast.tokens[1].value, ast.tokens[0].value).as_str();
} else if ast.tokens.len() == 1 && ast.tokens[0].token_type == TokenType::Round { } else if ast.tokens.len() == 1 && ast.tokens[0].token_type == TokenType::Round {
result += format!( result += format!(
"({})", "({})",
@@ -135,7 +137,8 @@ pub fn transpile_round(input: String, state: LexerState) -> String {
) )
.as_str(); .as_str();
} else { } else {
result += ast.tokens[0].value.as_str() result += ast.tokens[0].value.as_str();
result += " ";
} }
} }
BIN
View File
Binary file not shown.