Impl's and pointers
This commit is contained in:
+2
-2
@@ -88,7 +88,7 @@ const SYNTAX: [Node; 16] = [
|
||||
},
|
||||
Node {
|
||||
token_type: TokenType::Keyword1,
|
||||
token_regex: Lazy::new(|| Regex::new(r"^(namespace|if|for|while|else *if)\b").unwrap()),
|
||||
token_regex: Lazy::new(|| Regex::new(r"^(impl|namespace|if|for|while|else *if)\b").unwrap()),
|
||||
},
|
||||
Node {
|
||||
token_type: TokenType::Keyword2,
|
||||
@@ -96,7 +96,7 @@ const SYNTAX: [Node; 16] = [
|
||||
},
|
||||
Node {
|
||||
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_.:]*").unwrap()),
|
||||
},
|
||||
Node {
|
||||
token_type: TokenType::Number,
|
||||
|
||||
@@ -20,6 +20,7 @@ pub enum AstType {
|
||||
IncludeLocal,
|
||||
CodeBlock,
|
||||
Json,
|
||||
Impl,
|
||||
Other,
|
||||
}
|
||||
|
||||
@@ -110,6 +111,15 @@ impl Parser {
|
||||
ast_res.tokens.push(self.tokens[index + 2].clone());
|
||||
ast_res.ast_type = AstType::Namespace;
|
||||
self.index += 2;
|
||||
} else if self.tokens.len() - index > 2
|
||||
&& self.tokens[index].value == "impl"
|
||||
&& self.tokens[index + 1].token_type == TokenType::Identifier
|
||||
&& self.tokens[index + 2].token_type == TokenType::Curly
|
||||
{
|
||||
ast_res.tokens.push(self.tokens[index + 1].clone());
|
||||
ast_res.tokens.push(self.tokens[index + 2].clone());
|
||||
ast_res.ast_type = AstType::Impl;
|
||||
self.index += 2;
|
||||
} else if self.tokens.len() - index > 2
|
||||
&& self.tokens[index].token_type == TokenType::Keyword1
|
||||
&& self.tokens[index + 1].token_type == TokenType::Round
|
||||
@@ -175,6 +185,13 @@ impl Parser {
|
||||
ast_res.tokens[0].value += ">";
|
||||
ast_res.ast_type = AstType::VariableDeceleration;
|
||||
self.index += 2;
|
||||
} else if self.tokens.len() - index > 2
|
||||
&& self.tokens[index + 1].value == "*"
|
||||
&& self.tokens[index + 2].token_type == TokenType::Identifier {
|
||||
ast_res.tokens.push(self.tokens[index].clone());
|
||||
ast_res.tokens.push(self.tokens[index + 1].clone());
|
||||
ast_res.ast_type = AstType::PointerDeceleration;
|
||||
self.index += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -314,7 +314,21 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: &mut Op
|
||||
transpile(
|
||||
ast.tokens[1].value.clone(),
|
||||
0,
|
||||
LexerState { line: 1, column: 0 },
|
||||
state,
|
||||
options,
|
||||
),
|
||||
"}"
|
||||
)
|
||||
.as_str();
|
||||
} else if ast.ast_type == AstType::Impl {
|
||||
result += format!(
|
||||
"impl {} {}{}{}",
|
||||
&ast.tokens[0].value.clone(),
|
||||
"{",
|
||||
transpile(
|
||||
ast.tokens[1].value.clone(),
|
||||
0,
|
||||
state,
|
||||
options,
|
||||
),
|
||||
"}"
|
||||
|
||||
Reference in New Issue
Block a user