pointers
This commit is contained in:
+1
-1
@@ -87,7 +87,7 @@ const SYNTAX: [Node; 14] = [
|
||||
},
|
||||
Node {
|
||||
token_type: TokenType::Operator,
|
||||
token_regex: Lazy::new(|| Regex::new(r"^[|\-|\+|\*|\=|\!]").unwrap())
|
||||
token_regex: Lazy::new(|| Regex::new(r"^[|\-|\+|\*|\=|\!|\&]").unwrap())
|
||||
},
|
||||
Node {
|
||||
token_type: TokenType::Round,
|
||||
|
||||
@@ -8,6 +8,7 @@ pub enum AstType {
|
||||
FunctionDeceleration,
|
||||
VoidFunctionDeceleration,
|
||||
VariableDeceleration,
|
||||
PointerDeceleration,
|
||||
MutVariableDeceleration,
|
||||
Include,
|
||||
IncludeLocal,
|
||||
@@ -95,6 +96,10 @@ impl Parser {
|
||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
||||
ast_res.ast_type = AstType::MutVariableDeceleration;
|
||||
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
@@ -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();
|
||||
} else if ast.ast_type == AstType::MutVariableDeceleration {
|
||||
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 {
|
||||
result += format!(
|
||||
"({})",
|
||||
@@ -135,7 +137,8 @@ pub fn transpile_round(input: String, state: LexerState) -> String {
|
||||
)
|
||||
.as_str();
|
||||
} else {
|
||||
result += ast.tokens[0].value.as_str()
|
||||
result += ast.tokens[0].value.as_str();
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user