bug fix
This commit is contained in:
+1
-1
@@ -69,7 +69,7 @@ const SYNTAX: [Node; 12] = [
|
|||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Identifier,
|
token_type: TokenType::Identifier,
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^[._a-zA-Z][a-zA-Z0-9_]*").unwrap())
|
token_regex: Lazy::new(|| Regex::new(r"^[._a-zA-Z][a-zA-Z0-9_]*(:?<[._a-zA-Z][a-zA-Z0-9_<>]*>)?").unwrap())
|
||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Ptr,
|
token_type: TokenType::Ptr,
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ mod parser;
|
|||||||
use parser::Parser;
|
use parser::Parser;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let input = "int main() {}";
|
let input = "int<Test> 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());
|
||||||
|
|||||||
+5
-1
@@ -46,7 +46,7 @@ impl Parser {
|
|||||||
let token = &self.tokens[index];
|
let token = &self.tokens[index];
|
||||||
match token.token_type {
|
match token.token_type {
|
||||||
TokenType::Identifier => {
|
TokenType::Identifier => {
|
||||||
if self.tokens[index+1].token_type==TokenType::Identifier && self.tokens[index+2].token_type==TokenType::Round && self.tokens[index+3].token_type==TokenType::Curly {
|
if self.tokens.len()-index > 2 && self.tokens[index+1].token_type==TokenType::Identifier && self.tokens[index+2].token_type==TokenType::Round && self.tokens[index+3].token_type==TokenType::Curly {
|
||||||
ast_res.tokens.push(self.tokens[index].clone());
|
ast_res.tokens.push(self.tokens[index].clone());
|
||||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
ast_res.tokens.push(self.tokens[index+1].clone());
|
||||||
ast_res.tokens.push(self.tokens[index+2].clone());
|
ast_res.tokens.push(self.tokens[index+2].clone());
|
||||||
@@ -65,6 +65,10 @@ impl Parser {
|
|||||||
ast_res.tokens.push(ntk.clone());
|
ast_res.tokens.push(ntk.clone());
|
||||||
ast_res.ast_type = AstType::VariableDecleration;
|
ast_res.ast_type = AstType::VariableDecleration;
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
|
} else if ntk.token_type==TokenType::Keyword {
|
||||||
|
ast_res.tokens.push(ntk.clone());
|
||||||
|
ast_res.ast_type = AstType::VariableDecleration;
|
||||||
|
self.index += 1;
|
||||||
} else if ntk.token_type==TokenType::Angle {
|
} else if ntk.token_type==TokenType::Angle {
|
||||||
ast_res.tokens.push(ntk.clone());
|
ast_res.tokens.push(ntk.clone());
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user