forked from AbleOS/ableos
85 lines
1.7 KiB
Rust
85 lines
1.7 KiB
Rust
pub mod protocol;
|
|
|
|
use std::io::Read;
|
|
|
|
use {
|
|
logos::{Lexer, Logos},
|
|
protocol::Protocol,
|
|
};
|
|
|
|
#[derive(Logos, Debug, PartialEq, Clone)]
|
|
#[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,
|
|
|
|
#[token("{")]
|
|
LBrace,
|
|
|
|
#[token("}")]
|
|
RBrace,
|
|
|
|
#[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("[1234567890]+", |lex|{lex.slice().parse::<u64>().unwrap()})]
|
|
Number(u64),
|
|
|
|
#[regex(r"@[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
|
|
Decorator(String),
|
|
|
|
#[regex(r#"@[a-zA-Z_]+\([a-zA-Z,0-9=]+\)"#, |lex|{lex.slice().to_string()})]
|
|
DecoratorOption(String),
|
|
}
|
|
|
|
pub fn build_idl(name: String) {
|
|
let contents = open_protocol(name);
|
|
let lex = Token::lexer(&contents);
|
|
let mut tokens = vec![];
|
|
for x in lex {
|
|
match x {
|
|
Ok(token) => {
|
|
println!("{:?}", token);
|
|
tokens.push(token);
|
|
}
|
|
Err(err) => println!("{:?}", err),
|
|
}
|
|
}
|
|
build(tokens);
|
|
}
|
|
|
|
fn build(a: Vec<Token>) {
|
|
for toke in a {
|
|
println!("{:?}", toke);
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|