ableos/dev/src/idl/mod.rs

42 lines
958 B
Rust
Raw Normal View History

2024-08-30 12:31:45 -05:00
pub mod protocol;
use std::io::Read;
2024-08-30 07:38:04 -05:00
use logos::Logos;
#[derive(Logos, Debug, PartialEq)]
#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens
enum Token {
// Tokens can be literal strings, of any length.
#[token("protocol")]
Protocol,
2024-08-30 12:31:45 -05:00
#[token("{")]
LBrace,
#[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),
}
2024-08-30 07:38:04 -05:00
2024-08-30 12:31:45 -05:00
pub fn build_idl(name: String) {
let contents = open_protocol(name);
let lex = Token::lexer(&contents);
for x in lex {
println!("{:?}", x.unwrap());
}
2024-08-30 07:38:04 -05:00
}
2024-08-30 12:31:45 -05:00
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
2024-08-30 07:38:04 -05:00
}