namespaces
This commit is contained in:
+1
-1
@@ -88,7 +88,7 @@ const SYNTAX: [Node; 16] = [
|
||||
},
|
||||
Node {
|
||||
token_type: TokenType::Keyword1,
|
||||
token_regex: Lazy::new(|| Regex::new(r"^(if|for|while|else *if)\b").unwrap()),
|
||||
token_regex: Lazy::new(|| Regex::new(r"^(namespace|if|for|while|else *if)\b").unwrap()),
|
||||
},
|
||||
Node {
|
||||
token_type: TokenType::Keyword2,
|
||||
|
||||
@@ -10,6 +10,7 @@ pub enum AstType {
|
||||
StructCall,
|
||||
StructVar,
|
||||
VoidFunctionDeceleration,
|
||||
Namespace,
|
||||
VariableDeceleration,
|
||||
PointerDeceleration,
|
||||
MutVariableDeceleration,
|
||||
@@ -100,6 +101,15 @@ impl Parser {
|
||||
ast_res.tokens.push(self.tokens[index + 2].clone());
|
||||
ast_res.ast_type = AstType::StructDeceleration;
|
||||
self.index += 2;
|
||||
} else if self.tokens.len() - index > 2
|
||||
&& self.tokens[index].value == "namespace"
|
||||
&& 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::Namespace;
|
||||
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
|
||||
|
||||
+15
-1
@@ -41,7 +41,6 @@ pub fn transpile_mod(ast: Ast, options: &mut Options, s: &str) -> String {
|
||||
clean_incl(modfile.split(".").collect::<Vec<_>>()[0]),
|
||||
options.clone().modnum
|
||||
);
|
||||
println!("{}", s.to_string() + modfile);
|
||||
let file_content = fs::read_to_string(s.to_string() + modfile).expect("Error reading file");
|
||||
let transpiled_code = transpile(
|
||||
file_content,
|
||||
@@ -296,6 +295,21 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: &mut Op
|
||||
),
|
||||
)
|
||||
.as_str();
|
||||
} else if ast.ast_type == AstType::Namespace {
|
||||
let transpiled_code = transpile(
|
||||
ast.tokens[1].value.clone(),
|
||||
0,
|
||||
LexerState { line: 1, column: 0 },
|
||||
&mut Options::default(),
|
||||
);
|
||||
fs::write(
|
||||
("wyst_tmp/".to_string() + &ast.tokens[0].value.clone()) + ".rs",
|
||||
transpiled_code,
|
||||
)
|
||||
.expect("Error writing file");
|
||||
result += "mod ";
|
||||
result += &ast.tokens[0].value.clone();
|
||||
result += ";\n";
|
||||
}
|
||||
// flp
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user