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