diff --git a/lib/stdio.h b/lib/stdio.h new file mode 100644 index 0000000..e69de29 diff --git a/lib/stdio.rs b/lib/stdio.rs index 1e2f3de..78021bc 100644 --- a/lib/stdio.rs +++ b/lib/stdio.rs @@ -2,6 +2,6 @@ macro_rules! _0x7072696e7466 { ($($arg:tt)*) => { - print!($($arg)*); + print!($($arg)*) }; } diff --git a/src/transpiler.rs b/src/transpiler.rs index 302eeff..9d6fe9a 100644 --- a/src/transpiler.rs +++ b/src/transpiler.rs @@ -78,7 +78,27 @@ impl Transpiler { match t.as_rule() { Rule::identifier => { let ident = t.as_str().trim(); - let ident_rs = format!("_0x{}", hex::encode(ident.as_bytes())); + let mut ident_rs = String::from("_0x"); + let mut iter = ident.chars().peekable(); + while let Some(current) = iter.next() { + if iter.peek().is_some() { + let next = iter.next().unwrap(); + if current == '.' { + ident_rs += "._0x"; + } else if current == ':' && next == ':' { + ident_rs += "::_0x"; + } else { + ident_rs += hex::encode(current.to_string()).as_str(); + ident_rs += hex::encode(next.to_string()).as_str(); + } + } else { + if current == '.' { + ident_rs += "._0x"; + } else { + ident_rs += hex::encode(current.to_string()).as_str(); + } + } + } if self.mod_manager.macros.contains(&ident_rs) { output += ident_rs.as_str(); output += "!"; @@ -119,6 +139,13 @@ impl Transpiler { } res } + pub fn transpile_vec(&mut self, pairs: Vec>) -> String { + let mut res = String::new(); + for pair in pairs { + res += self.transpile(pair).as_str(); + } + res + } pub fn transpile(&mut self, pair: Pair) -> String { let mut res = String::new(); let tokens = to_indexable(pair.clone().into_inner()); @@ -223,7 +250,34 @@ impl Transpiler { ); } + Rule::enum_def => { + res += format!( + "enum {} {}{}{}", + self.transpile(tokens[0].clone()), + "{", + self.transpile_pairs(tokens[1].clone().into_inner()), + "}\n" + ) + .as_str(); + } + + Rule::ecall => { + res += self.transpile(tokens[0].clone()).as_str(); + if tokens.len() > 1 { + let mut params = tokens.clone(); + params.remove(0); + res += "("; + res += self.transpile_vec(params).as_str(); + res += ")"; + } + } + + Rule::comma => { + res += ","; + } + _ => { + println!("\x1b[33mUnh: {}\x1b[0m", pair); res += " "; res += pair.as_str(); res += " "; diff --git a/src/wyst.pest b/src/wyst.pest index 30df927..2b9bf25 100644 --- a/src/wyst.pest +++ b/src/wyst.pest @@ -4,6 +4,7 @@ wspc = { " " | "\t" | "\n" } // [chars] comma = {","} semicolon = {";"} +dot = {"."} // [literals] filepath = { ("/"|('a'..'z' | 'a'..'z' | '0'..'9' | "_" | "-" | "."))+ } @@ -36,6 +37,9 @@ 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 } +ecall = { identifier ~ ( "(" ~ ((def_identifier ~ comma)* ~ def_identifier?) ~ ")" )? } +ecurly = { "{" ~ ((ecall ~ comma)* ~ ecall?) ~ "}" } +enum_def = { "enum" ~ identifier ~ ecurly } rust_macro_lint = { "macro_rules" ~ "!" ~ identifier } rust_code = { (rust_macro_lint | ANY)* } @@ -59,6 +63,7 @@ expr_ = { expr = { (expr_ ~ plus ~ expr_) | + (expr_ ~ dot ~ identifier ~ round?) | expr_ } @@ -77,6 +82,7 @@ top_expr = { include_global | func_def | struct_def | + enum_def | map )* ~ !ANY }