small features
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ use compiler::{compile_rust, transpile_file};
|
||||
fn main() {
|
||||
let matches = App::new("Wyst")
|
||||
.version("0.51")
|
||||
.author("Leo dev")
|
||||
.author("Orus")
|
||||
.about("The wyst compiler")
|
||||
.arg(
|
||||
Arg::with_name("file")
|
||||
|
||||
+31
-1
@@ -91,7 +91,20 @@ impl Transpiler {
|
||||
.as_str();
|
||||
}
|
||||
Rule::var_def => {
|
||||
res += format!("let mut {}: {}", tokens[1].as_str(), tokens[0].as_str()).as_str();
|
||||
res += format!(
|
||||
"let mut {}: {}",
|
||||
self.transpile(tokens[1].clone()),
|
||||
self.transpile(tokens[0].clone())
|
||||
)
|
||||
.as_str();
|
||||
}
|
||||
Rule::var_def_set => {
|
||||
res += format!(
|
||||
"{} = {}",
|
||||
self.transpile(tokens[0].clone()),
|
||||
self.transpile(tokens[1].clone()),
|
||||
)
|
||||
.as_str();
|
||||
}
|
||||
Rule::curly => {
|
||||
res += "{";
|
||||
@@ -128,6 +141,7 @@ impl Transpiler {
|
||||
} else {
|
||||
res += match ident {
|
||||
"void" => "()",
|
||||
"int" => "i32",
|
||||
_ => ident_rs.as_str(),
|
||||
};
|
||||
}
|
||||
@@ -153,6 +167,22 @@ impl Transpiler {
|
||||
res += self.transpile_pairs(pair.into_inner()).as_str();
|
||||
}
|
||||
|
||||
Rule::struct_def => {
|
||||
res += "struct ";
|
||||
res += self.transpile(tokens[0].clone()).as_str();
|
||||
res += "{";
|
||||
res += self.transpile(tokens[1].clone()).as_str();
|
||||
res += "}";
|
||||
}
|
||||
|
||||
Rule::semicolon => {
|
||||
res += ";\n";
|
||||
}
|
||||
|
||||
Rule::string => {
|
||||
res += pair.as_str();
|
||||
}
|
||||
|
||||
_ => {
|
||||
res += " ";
|
||||
res += pair.as_str();
|
||||
|
||||
+6
-1
@@ -1,4 +1,5 @@
|
||||
WHITESPACE = _{ " " | "\t" | "\n" }
|
||||
wspc = { " " | "\t" | "\n" }
|
||||
|
||||
// [chars]
|
||||
comma = {","}
|
||||
@@ -15,6 +16,7 @@ raw_string = { (!("\\" | "\"") ~ ANY)+ }
|
||||
string = { "\"" ~ (raw_string | escape )* ~ "\"" }
|
||||
char = { "'" ~ (escape | ANY) ~ "'" }
|
||||
bool = @{"true" | "false"}
|
||||
keyword = @{"struct"}
|
||||
|
||||
// [numbers]
|
||||
hex = @{ "0" ~ ("x"|"X") ~ ('0'..'9' | 'a'..'f' | 'A'..'F')*}
|
||||
@@ -27,10 +29,12 @@ def_identifier = {identifier ~ ("<" ~ ((def_identifier ~ comma)* ~ def_identifie
|
||||
|
||||
// [definitions]
|
||||
round_def = { "(" ~ ((var_def ~ comma)* ~ var_def?) ~ ")" }
|
||||
curly_def = { "{" ~ (var_def ~ semicolon)* ~ "}" }
|
||||
var_def = { def_identifier ~ identifier }
|
||||
var_def_set = { var_def ~ "=" ~ expr }
|
||||
var_set = { def_identifier ~ "=" ~ expr }
|
||||
func_def = { def_identifier ~ identifier ~ round_def ~ curly }
|
||||
struct_def = { "struct" ~ identifier ~ curly_def }
|
||||
|
||||
rust_macro_lint = { "macro_rules" ~ "!" ~ identifier }
|
||||
rust_code = { (rust_macro_lint | ANY)* }
|
||||
@@ -70,6 +74,7 @@ top_expr = {
|
||||
(
|
||||
include |
|
||||
include_global |
|
||||
func_def
|
||||
func_def |
|
||||
struct_def
|
||||
)* ~ !ANY
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user