From 6a94aa3e84fdcc36bae9ca8c17a6aacb98e44062 Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 4 May 2023 02:27:04 -0500 Subject: [PATCH] aidl initial work --- Cargo.lock | 7 ++++ Cargo.toml | 1 + programs/aidl/Cargo.toml | 9 +++++ programs/aidl/README.md | 3 ++ programs/aidl/SPEC.md | 22 +++++++++++ programs/aidl/assets/core.idl | 20 ++++++++++ programs/aidl/assets/examples.idl | 13 +++++++ programs/aidl/assets/minimal.idl | 1 + programs/aidl/assets/vfs.idl | 24 ++++++++++++ programs/aidl/src/main.rs | 62 +++++++++++++++++++++++++++++++ 10 files changed, 162 insertions(+) create mode 100644 programs/aidl/Cargo.toml create mode 100644 programs/aidl/README.md create mode 100644 programs/aidl/SPEC.md create mode 100644 programs/aidl/assets/core.idl create mode 100644 programs/aidl/assets/examples.idl create mode 100644 programs/aidl/assets/minimal.idl create mode 100644 programs/aidl/assets/vfs.idl create mode 100644 programs/aidl/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index e179cfe..d8b2084 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,13 @@ dependencies = [ "version_check", ] +[[package]] +name = "aidl" +version = "0.1.0" +dependencies = [ + "logos 0.13.0", +] + [[package]] name = "anyhow" version = "1.0.66" diff --git a/Cargo.toml b/Cargo.toml index 8cc6f7e..0297fd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ members = [ "libraries/uri", "libraries/versioning", + "programs/aidl", "programs/ari_client", "programs/ari_server", "programs/axel2wat", diff --git a/programs/aidl/Cargo.toml b/programs/aidl/Cargo.toml new file mode 100644 index 0000000..5596c9f --- /dev/null +++ b/programs/aidl/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aidl" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +logos = "0.13.0" diff --git a/programs/aidl/README.md b/programs/aidl/README.md new file mode 100644 index 0000000..c6b3aa4 --- /dev/null +++ b/programs/aidl/README.md @@ -0,0 +1,3 @@ +### Inspirations +- [FIDL](https://fuchsia.dev/fuchsia-src/concepts/fidl/overview) +- [rtps-idl](https://crates.io/crates/rtps-idl) diff --git a/programs/aidl/SPEC.md b/programs/aidl/SPEC.md new file mode 100644 index 0000000..ae2279a --- /dev/null +++ b/programs/aidl/SPEC.md @@ -0,0 +1,22 @@ +The example implementation will be in rust + + + +IDL | Rust +__________ +boolean | bool +I8 | i8 +I16 | i16 +I32 | i32 +I64 | i64 +U8 | u8 +U16 | u16 +U32 | u32 +U64 | u64 +F32 | f32 +F64 | f64 +Constant X Y Z | const X: Y = Z; +Type | type +Vector | Vec +Array[X;Y] | [X;Y] +Function X accepts(YX) returns(ZX) | fn X(YX) -> ZX diff --git a/programs/aidl/assets/core.idl b/programs/aidl/assets/core.idl new file mode 100644 index 0000000..eaebf0c --- /dev/null +++ b/programs/aidl/assets/core.idl @@ -0,0 +1,20 @@ +Type Byte = U8; +Type String = Vector; + +Enumurate Boolean{ + False = 0, + True = 1, +} + +Union Option{ + None, + Some +} + + + +Structure Version { + major: Byte, + minor: Byte, + patch: Byte, +}; \ No newline at end of file diff --git a/programs/aidl/assets/examples.idl b/programs/aidl/assets/examples.idl new file mode 100644 index 0000000..b4070ea --- /dev/null +++ b/programs/aidl/assets/examples.idl @@ -0,0 +1,13 @@ +Type UUID = Array[U8; 16]; + +Type Nanoseconds = U32; + +Structure Duration{ + secs: U64, + nanos: Nanoseconds, +} + +Structure LinkedList{ + data: Any, + child: Option, +} \ No newline at end of file diff --git a/programs/aidl/assets/minimal.idl b/programs/aidl/assets/minimal.idl new file mode 100644 index 0000000..65ad57d --- /dev/null +++ b/programs/aidl/assets/minimal.idl @@ -0,0 +1 @@ +Type Byte = U8; diff --git a/programs/aidl/assets/vfs.idl b/programs/aidl/assets/vfs.idl new file mode 100644 index 0000000..c766843 --- /dev/null +++ b/programs/aidl/assets/vfs.idl @@ -0,0 +1,24 @@ +// core provides lots of useful types like String and Byte +use core; + +Constant VERSION Version{ + major: 1, + minor: 0, + patch: 0, +} + +Type Path = String; + +Structure File { + name: String, + data: Vector, +} + +Interface File{ + function new accepts(Path) returns(None); + + // Open in this iteration assumes the file exists + function open accepts(Path) returns(File); + + function close accepts(File) returns(None); +} \ No newline at end of file diff --git a/programs/aidl/src/main.rs b/programs/aidl/src/main.rs new file mode 100644 index 0000000..c3e2ccc --- /dev/null +++ b/programs/aidl/src/main.rs @@ -0,0 +1,62 @@ +use logos::Logos; + +#[derive(Logos, Debug, PartialEq)] +#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens +enum Token { + #[token("{")] + LeftBrace, + + #[token("}")] + RightBrace, + + #[token("(")] + LeftParen, + + #[token(")")] + RightParen, + + #[token(";")] + Semicolon, + + #[token(":")] + Colon, + + #[token("<")] + LeftArrow, + + #[token(">")] + RightArrow, + + #[token(",")] + Comma, + + #[token("=")] + Equals, + + #[regex(r#"[A-z]+"#, |lex| lex.slice().parse().ok())] + Literal(String), + + #[regex("use [a-zA-Z/]+;", |lex| lex.slice().parse().ok())] + Component(String), + + #[regex("U[0-9]+", |lex| lex.slice().parse().ok())] + UnsignedType(String), + + #[regex("I[0-9]+", |lex| lex.slice().parse().ok())] + SignedType(String), + + #[regex(r"//[ a-zA-Z!-+]+", |lex| lex.slice().parse().ok())] + Comment(String), +} + +fn main() { + let mut lex = Token::lexer(include_str!("../../../programs/aidl/assets/vfs.idl")); + + for token in lex { + // let ok_token = token.ok(); + // if ok_token.is_some() { + // println!("{:?}", ok_token.unwrap()); + // } + println!("{:?}", token); + } +}