mut declerations
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ mod parser;
|
|||||||
use parser::Parser;
|
use parser::Parser;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let input = "int mut x";
|
let input = "int<x> mut x";
|
||||||
println!("\n\n\n\n");
|
println!("\n\n\n\n");
|
||||||
let tokens = lex(input, false);
|
let tokens = lex(input, false);
|
||||||
let mut ast = Parser::new(tokens.clone());
|
let mut ast = Parser::new(tokens.clone());
|
||||||
|
|||||||
+6
-7
@@ -1,10 +1,11 @@
|
|||||||
use crate::lexer::{Token, TokenType};
|
use crate::lexer::{Token, TokenType};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum AstType {
|
pub enum AstType {
|
||||||
FunctionDeceleration,
|
FunctionDeceleration,
|
||||||
VariableDeceleration,
|
VariableDeceleration,
|
||||||
|
MutVariableDeceleration,
|
||||||
Other
|
Other
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,14 +76,12 @@ impl Parser {
|
|||||||
self.index += 1;
|
self.index += 1;
|
||||||
} else if ntk.token_type==TokenType::Identifier {
|
} else if ntk.token_type==TokenType::Identifier {
|
||||||
ast_res.tokens.push(ntk.clone());
|
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;
|
ast_res.ast_type = AstType::VariableDeceleration;
|
||||||
|
}
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
} else if ntk.token_type==TokenType::Keyword {
|
} else if ntk.value=="mut" {
|
||||||
ast_res.tokens.push(ntk.clone());
|
ast_res.ast_type = AstType::MutVariableDeceleration;
|
||||||
ast_res.ast_type = AstType::VariableDeceleration;
|
|
||||||
self.index += 1;
|
|
||||||
} else if ntk.token_type==TokenType::Angle {
|
|
||||||
ast_res.tokens.push(ntk.clone());
|
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
} else {
|
} else {
|
||||||
self.index -= 1;
|
self.index -= 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user