diff --git a/dev/src/idl/mod.rs b/dev/src/idl/mod.rs index 69b65238..a4299aeb 100644 --- a/dev/src/idl/mod.rs +++ b/dev/src/idl/mod.rs @@ -1,3 +1,7 @@ +pub mod protocol; + +use std::io::Read; + use logos::Logos; #[derive(Logos, Debug, PartialEq)] @@ -7,14 +11,31 @@ enum Token { #[token("protocol")] Protocol, - #[token(".")] - Period, + #[token("{")] + LBrace, - // Or regular expressions. - #[regex("[a-zA-Z]+")] - Text, + #[token("}")] + RBrace, + + #[regex("[a-zA-Z]+", |lex|{lex.slice().to_string()})] + Text(String), + + #[regex(r#"@[a-zA-Z]+\(?[a-zA-Z]+\)?"#, |lex|{lex.slice().to_string()})] + Decorator(String), } -pub fn main() { - let mut lex = Token::lexer("Create ridiculously fast Lexers."); +pub fn build_idl(name: String) { + let contents = open_protocol(name); + let lex = Token::lexer(&contents); + for x in lex { + println!("{:?}", x.unwrap()); + } +} + +fn open_protocol(name: String) -> String { + let path = format!("sysdata/idl/{}/src/protocol.aidl", name); + let mut file = std::fs::File::open(path).unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + contents } diff --git a/dev/src/idl/protocol.rs b/dev/src/idl/protocol.rs new file mode 100644 index 00000000..191e504a --- /dev/null +++ b/dev/src/idl/protocol.rs @@ -0,0 +1,22 @@ +pub enum ProtocolTypes { + Byte, +} + +pub struct Decorator { + pub name: String, + pub value: Option, +} + +pub struct Protocol { + pub name: String, + pub decorators: Vec, +} + +pub struct Field { + pub name: String, + pub ptype: ProtocolTypes, +} + +pub struct Structure { + pub fields: Vec, +} diff --git a/dev/src/main.rs b/dev/src/main.rs index 8e27d722..42406436 100644 --- a/dev/src/main.rs +++ b/dev/src/main.rs @@ -1,4 +1,6 @@ use std::io::Write; + +use idl::build_idl; pub mod idl; pub enum Options { @@ -7,7 +9,7 @@ pub enum Options { New, Run, } -#[derive(PartialEq)] +#[derive(PartialEq, Debug)] pub enum DevelopmentType { Program, Library, @@ -24,7 +26,7 @@ fn main() { match subcommand { "build" => { - let name = &args[1]; + let name = &args.pop().unwrap(); build(name.to_string()) } "new" => { @@ -103,8 +105,21 @@ fn run() { fn build(name: String) { println!("building {}", name); + let mut a = name.split("/"); + let dev_type = a.next().unwrap(); + let name = a.next().unwrap().to_string(); + match dev_type { + "programs" => build_program(name), + "idl" => build_idl(name), + _ => { + panic!() + } + } } +pub fn build_program(name: String) {} +pub fn build_library(name: String) {} + fn help() { println!( "========== diff --git a/sysdata/idl/abc/src/protocol.aidl b/sysdata/idl/abc/src/protocol.aidl index b08bdcf1..8bff36de 100644 --- a/sysdata/idl/abc/src/protocol.aidl +++ b/sysdata/idl/abc/src/protocol.aidl @@ -1,2 +1,6 @@ + +@visibility(public) protocol abc { - } \ No newline at end of file + + +} \ No newline at end of file