aidl initial work
This commit is contained in:
parent
10d4c4c32c
commit
6a94aa3e84
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -32,6 +32,7 @@ members = [
|
|||
"libraries/uri",
|
||||
"libraries/versioning",
|
||||
|
||||
"programs/aidl",
|
||||
"programs/ari_client",
|
||||
"programs/ari_server",
|
||||
"programs/axel2wat",
|
||||
|
|
9
programs/aidl/Cargo.toml
Normal file
9
programs/aidl/Cargo.toml
Normal file
|
@ -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"
|
3
programs/aidl/README.md
Normal file
3
programs/aidl/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
### Inspirations
|
||||
- [FIDL](https://fuchsia.dev/fuchsia-src/concepts/fidl/overview)
|
||||
- [rtps-idl](https://crates.io/crates/rtps-idl)
|
22
programs/aidl/SPEC.md
Normal file
22
programs/aidl/SPEC.md
Normal file
|
@ -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<X> | Vec<X>
|
||||
Array[X;Y] | [X;Y]
|
||||
Function X accepts(YX) returns(ZX) | fn X(YX) -> ZX
|
20
programs/aidl/assets/core.idl
Normal file
20
programs/aidl/assets/core.idl
Normal file
|
@ -0,0 +1,20 @@
|
|||
Type Byte = U8;
|
||||
Type String = Vector<Byte>;
|
||||
|
||||
Enumurate Boolean{
|
||||
False = 0,
|
||||
True = 1,
|
||||
}
|
||||
|
||||
Union Option<T>{
|
||||
None,
|
||||
Some<T>
|
||||
}
|
||||
|
||||
|
||||
|
||||
Structure Version {
|
||||
major: Byte,
|
||||
minor: Byte,
|
||||
patch: Byte,
|
||||
};
|
13
programs/aidl/assets/examples.idl
Normal file
13
programs/aidl/assets/examples.idl
Normal file
|
@ -0,0 +1,13 @@
|
|||
Type UUID = Array[U8; 16];
|
||||
|
||||
Type Nanoseconds = U32;
|
||||
|
||||
Structure Duration{
|
||||
secs: U64,
|
||||
nanos: Nanoseconds,
|
||||
}
|
||||
|
||||
Structure LinkedList{
|
||||
data: Any,
|
||||
child: Option<LinkedList>,
|
||||
}
|
1
programs/aidl/assets/minimal.idl
Normal file
1
programs/aidl/assets/minimal.idl
Normal file
|
@ -0,0 +1 @@
|
|||
Type Byte = U8;
|
24
programs/aidl/assets/vfs.idl
Normal file
24
programs/aidl/assets/vfs.idl
Normal file
|
@ -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<Byte>,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
62
programs/aidl/src/main.rs
Normal file
62
programs/aidl/src/main.rs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue