angle brackets
This commit is contained in:
+28
-3
@@ -1,7 +1,6 @@
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
pub struct LexerState {
|
pub struct LexerState {
|
||||||
pub line: usize,
|
pub line: usize,
|
||||||
pub column: usize
|
pub column: usize
|
||||||
@@ -22,6 +21,7 @@ pub enum TokenType {
|
|||||||
Round,
|
Round,
|
||||||
Curly,
|
Curly,
|
||||||
Square,
|
Square,
|
||||||
|
Angle,
|
||||||
Include,
|
Include,
|
||||||
String,
|
String,
|
||||||
Comment,
|
Comment,
|
||||||
@@ -72,11 +72,11 @@ const SYNTAX: [Node; 14] = [
|
|||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Keyword,
|
token_type: TokenType::Keyword,
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^(mut|try|catch|return|fn|let)\b").unwrap())
|
token_regex: Lazy::new(|| Regex::new(r"^(mut|try|catch|return|fn|let|use)\b").unwrap())
|
||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Identifier,
|
token_type: TokenType::Identifier,
|
||||||
token_regex: Lazy::new(|| Regex::new(r"^[._a-zA-Z][a-zA-Z0-9_]*(:?\s*<[._a-zA-Z][a-zA-Z0-9_<>]*>)?").unwrap())
|
token_regex: Lazy::new(|| Regex::new(r"^[._a-zA-Z][a-zA-Z0-9_]*").unwrap())
|
||||||
},
|
},
|
||||||
Node {
|
Node {
|
||||||
token_type: TokenType::Number,
|
token_type: TokenType::Number,
|
||||||
@@ -287,6 +287,31 @@ pub fn lex(mut code: &str, use_whitespace: bool, state: LexerState) -> Result<Ve
|
|||||||
} else {brstr += fch.as_str();}
|
} else {brstr += fch.as_str();}
|
||||||
} else {brstr += fch.as_str();}
|
} else {brstr += fch.as_str();}
|
||||||
}
|
}
|
||||||
|
"<" => {
|
||||||
|
code = code.strip_prefix(fch.as_str()).expect("");
|
||||||
|
if brln > 0 {
|
||||||
|
brstr += fch.as_str();
|
||||||
|
} else {
|
||||||
|
br_state.line = state.line;
|
||||||
|
br_state.column = state.column;
|
||||||
|
}
|
||||||
|
brtp.push(6);
|
||||||
|
}
|
||||||
|
">" => {
|
||||||
|
code = code.strip_prefix(fch.as_str()).expect("");
|
||||||
|
if brln > 0 && brtp[brln-1] == 6 {
|
||||||
|
brtp.pop();
|
||||||
|
if brln == 1 {
|
||||||
|
tokens.push(Token {
|
||||||
|
token_type: TokenType::Angle,
|
||||||
|
value: brstr.clone(),
|
||||||
|
column: br_state.column,
|
||||||
|
line: br_state.line
|
||||||
|
});
|
||||||
|
brstr = String::new();
|
||||||
|
} else {brstr += fch.as_str();}
|
||||||
|
} else {brstr += fch.as_str();}
|
||||||
|
}
|
||||||
"\\" => {
|
"\\" => {
|
||||||
brstr += "\\";
|
brstr += "\\";
|
||||||
code = code.strip_prefix(fch.as_str()).expect("");
|
code = code.strip_prefix(fch.as_str()).expect("");
|
||||||
|
|||||||
@@ -92,6 +92,13 @@ impl Parser {
|
|||||||
ast_res.tokens.push(self.tokens[index+1].clone());
|
ast_res.tokens.push(self.tokens[index+1].clone());
|
||||||
ast_res.ast_type = AstType::VariableDeceleration;
|
ast_res.ast_type = AstType::VariableDeceleration;
|
||||||
self.index += 1;
|
self.index += 1;
|
||||||
|
} else if self.tokens[index+2].token_type==TokenType::Identifier && self.tokens[index+1].token_type==TokenType::Angle {
|
||||||
|
ast_res.tokens.push(self.tokens[index+2].clone());
|
||||||
|
ast_res.tokens[0].value += "<";
|
||||||
|
ast_res.tokens[0].value += self.tokens[index+1].value.as_str();
|
||||||
|
ast_res.tokens[0].value += ">";
|
||||||
|
ast_res.ast_type = AstType::VariableDeceleration;
|
||||||
|
self.index += 2;
|
||||||
} else if self.tokens[index+1].value=="mut" && self.tokens[index+2].token_type==TokenType::Identifier {
|
} else if self.tokens[index+1].value=="mut" && self.tokens[index+2].token_type==TokenType::Identifier {
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user