From 1855307cd90fa5e31cbc8d006fad1f364f9fa863 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 2 Sep 2024 21:50:43 -0500 Subject: [PATCH] IDL tokenization --- dev/src/idl/mod.rs | 35 +++++++++++++++++++++++++++--- dev/src/idl/protocol.rs | 10 +++------ sysdata/idl/abc/src/protocol.aidl | 6 ----- sysdata/idl/{abc => log}/README.md | 0 sysdata/idl/log/src/protocol.aidl | 24 ++++++++++++++++++++ 5 files changed, 59 insertions(+), 16 deletions(-) delete mode 100644 sysdata/idl/abc/src/protocol.aidl rename sysdata/idl/{abc => log}/README.md (100%) create mode 100644 sysdata/idl/log/src/protocol.aidl diff --git a/dev/src/idl/mod.rs b/dev/src/idl/mod.rs index a4299aeb..438ac881 100644 --- a/dev/src/idl/mod.rs +++ b/dev/src/idl/mod.rs @@ -17,18 +17,47 @@ enum Token { #[token("}")] RBrace, - #[regex("[a-zA-Z]+", |lex|{lex.slice().to_string()})] + #[token("(")] + LParen, + + #[token(")")] + RParen, + + #[token(":")] + Colon, + #[token(";")] + SemiColon, + + #[token(",")] + Comma, + + #[token("=")] + Equal, + + #[token("->")] + RArrow, + + #[regex("[a-zA-Z_]+", |lex|{lex.slice().to_string()})] Text(String), - #[regex(r#"@[a-zA-Z]+\(?[a-zA-Z]+\)?"#, |lex|{lex.slice().to_string()})] + #[regex("[1234567890]+")] + Number, + + #[regex(r"@[a-zA-Z_]+", |lex|{lex.slice().to_string()})] Decorator(String), + + #[regex(r#"@[a-zA-Z_]+\([a-zA-Z]+\)"#, |lex|{lex.slice().to_string()})] + DecoratorOption(String), } pub fn build_idl(name: String) { let contents = open_protocol(name); let lex = Token::lexer(&contents); for x in lex { - println!("{:?}", x.unwrap()); + match x { + Ok(token) => println!("{:?}", token), + Err(err) => println!("{:?}", err), + } } } diff --git a/dev/src/idl/protocol.rs b/dev/src/idl/protocol.rs index 191e504a..1d0fa14a 100644 --- a/dev/src/idl/protocol.rs +++ b/dev/src/idl/protocol.rs @@ -12,11 +12,7 @@ pub struct Protocol { pub decorators: Vec, } -pub struct Field { - pub name: String, - pub ptype: ProtocolTypes, -} - -pub struct Structure { - pub fields: Vec, +pub struct IDLEnum { + pub name: String, + pub accepted_values: Vec<(String, u64)>, } diff --git a/sysdata/idl/abc/src/protocol.aidl b/sysdata/idl/abc/src/protocol.aidl deleted file mode 100644 index 8bff36de..00000000 --- a/sysdata/idl/abc/src/protocol.aidl +++ /dev/null @@ -1,6 +0,0 @@ - -@visibility(public) -protocol abc { - - -} \ No newline at end of file diff --git a/sysdata/idl/abc/README.md b/sysdata/idl/log/README.md similarity index 100% rename from sysdata/idl/abc/README.md rename to sysdata/idl/log/README.md diff --git a/sysdata/idl/log/src/protocol.aidl b/sysdata/idl/log/src/protocol.aidl new file mode 100644 index 00000000..ec37b5bd --- /dev/null +++ b/sysdata/idl/log/src/protocol.aidl @@ -0,0 +1,24 @@ +@auto_increment +enum LogLevel { + Error = 0, + Warn, + Info, + Debug, + Trace, +} + +@auto_increment +enum LogResult { + Err = 0, + Ok, +} + +struct Log { + log_level: LogLevel, +} + +@visibility(public) +protocol Log { + fn log(Log) -> LogResult; + fn flush() -> LogResult; +} \ No newline at end of file