auto pub on namespaces
This commit is contained in:
+15
-1
@@ -6,6 +6,7 @@ use std::fs;
|
|||||||
pub struct Options {
|
pub struct Options {
|
||||||
auto_mut: bool,
|
auto_mut: bool,
|
||||||
auto_macro: bool,
|
auto_macro: bool,
|
||||||
|
auto_pub: bool,
|
||||||
macros: Vec<String>,
|
macros: Vec<String>,
|
||||||
modnum: u32,
|
modnum: u32,
|
||||||
}
|
}
|
||||||
@@ -15,6 +16,7 @@ impl Default for Options {
|
|||||||
Options {
|
Options {
|
||||||
auto_mut: true,
|
auto_mut: true,
|
||||||
auto_macro: true,
|
auto_macro: true,
|
||||||
|
auto_pub: false,
|
||||||
macros: vec![String::from("println")],
|
macros: vec![String::from("println")],
|
||||||
modnum: 0,
|
modnum: 0,
|
||||||
}
|
}
|
||||||
@@ -99,6 +101,9 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: &mut Op
|
|||||||
};
|
};
|
||||||
|
|
||||||
if ast.ast_type == AstType::FunctionDeceleration {
|
if ast.ast_type == AstType::FunctionDeceleration {
|
||||||
|
if options.auto_pub {
|
||||||
|
result += "pub ";
|
||||||
|
}
|
||||||
result += format!(
|
result += format!(
|
||||||
"fn {}({}) -> {} {}",
|
"fn {}({}) -> {} {}",
|
||||||
ast.tokens[1].value,
|
ast.tokens[1].value,
|
||||||
@@ -122,6 +127,9 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: &mut Op
|
|||||||
)
|
)
|
||||||
.as_str();
|
.as_str();
|
||||||
} else if ast.ast_type == AstType::VoidFunctionDeceleration {
|
} else if ast.ast_type == AstType::VoidFunctionDeceleration {
|
||||||
|
if options.auto_pub {
|
||||||
|
result += "pub ";
|
||||||
|
}
|
||||||
result += format!(
|
result += format!(
|
||||||
"fn {}({}) {}",
|
"fn {}({}) {}",
|
||||||
ast.tokens[1].value,
|
ast.tokens[1].value,
|
||||||
@@ -144,6 +152,9 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: &mut Op
|
|||||||
)
|
)
|
||||||
.as_str();
|
.as_str();
|
||||||
} else if ast.ast_type == AstType::StructDeceleration {
|
} else if ast.ast_type == AstType::StructDeceleration {
|
||||||
|
if options.auto_pub {
|
||||||
|
result += "pub ";
|
||||||
|
}
|
||||||
result += format!(
|
result += format!(
|
||||||
"struct {} {} {}",
|
"struct {} {} {}",
|
||||||
ast.tokens[0].value,
|
ast.tokens[0].value,
|
||||||
@@ -296,12 +307,15 @@ pub fn transpile(input: String, indent: u32, state: LexerState, options: &mut Op
|
|||||||
)
|
)
|
||||||
.as_str();
|
.as_str();
|
||||||
} else if ast.ast_type == AstType::Namespace {
|
} else if ast.ast_type == AstType::Namespace {
|
||||||
|
let l_opt = options.auto_pub;
|
||||||
|
options.auto_pub = true;
|
||||||
let transpiled_code = transpile(
|
let transpiled_code = transpile(
|
||||||
ast.tokens[1].value.clone(),
|
ast.tokens[1].value.clone(),
|
||||||
0,
|
0,
|
||||||
LexerState { line: 1, column: 0 },
|
LexerState { line: 1, column: 0 },
|
||||||
&mut Options::default(),
|
options,
|
||||||
);
|
);
|
||||||
|
options.auto_pub = l_opt;
|
||||||
fs::write(
|
fs::write(
|
||||||
("wyst_tmp/".to_string() + &ast.tokens[0].value.clone()) + ".rs",
|
("wyst_tmp/".to_string() + &ast.tokens[0].value.clone()) + ".rs",
|
||||||
transpiled_code,
|
transpiled_code,
|
||||||
|
|||||||
Reference in New Issue
Block a user