ableos/dev/src/idl/mod.rs

71 lines
1.4 KiB
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,
2024-09-02 21:50:43 -05:00
#[token("(")]
LParen,
#[token(")")]
RParen,
#[token(":")]
Colon,
#[token(";")]
SemiColon,
#[token(",")]
Comma,
#[token("=")]
Equal,
#[token("->")]
RArrow,
#[regex("[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
2024-08-30 12:31:45 -05:00
Text(String),
2024-09-02 21:50:43 -05:00
#[regex("[1234567890]+")]
Number,
#[regex(r"@[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
2024-08-30 12:31:45 -05:00
Decorator(String),
2024-09-02 21:50:43 -05:00
#[regex(r#"@[a-zA-Z_]+\([a-zA-Z]+\)"#, |lex|{lex.slice().to_string()})]
DecoratorOption(String),
2024-08-30 12:31:45 -05:00
}
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 {
2024-09-02 21:50:43 -05:00
match x {
Ok(token) => println!("{:?}", token),
Err(err) => println!("{:?}", err),
}
2024-08-30 12:31:45 -05:00
}
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
}