1
0
Fork 0
forked from koniifer/ableos
This commit is contained in:
Able 2024-09-03 03:34:29 -05:00
parent 1855307cd9
commit 0594b99a59
2 changed files with 31 additions and 18 deletions

View file

@ -2,9 +2,12 @@ pub mod protocol;
use std::io::Read; use std::io::Read;
use logos::Logos; use {
logos::{Lexer, Logos},
protocol::Protocol,
};
#[derive(Logos, Debug, PartialEq)] #[derive(Logos, Debug, PartialEq, Clone)]
#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens #[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens
enum Token { enum Token {
// Tokens can be literal strings, of any length. // Tokens can be literal strings, of any length.
@ -40,25 +43,36 @@ enum Token {
#[regex("[a-zA-Z_]+", |lex|{lex.slice().to_string()})] #[regex("[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
Text(String), Text(String),
#[regex("[1234567890]+")] #[regex("[1234567890]+", |lex|{lex.slice().parse::<u64>().unwrap()})]
Number, Number(u64),
#[regex(r"@[a-zA-Z_]+", |lex|{lex.slice().to_string()})] #[regex(r"@[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
Decorator(String), Decorator(String),
#[regex(r#"@[a-zA-Z_]+\([a-zA-Z]+\)"#, |lex|{lex.slice().to_string()})] #[regex(r#"@[a-zA-Z_]+\([a-zA-Z,0-9=]+\)"#, |lex|{lex.slice().to_string()})]
DecoratorOption(String), DecoratorOption(String),
} }
pub fn build_idl(name: String) { pub fn build_idl(name: String) {
let contents = open_protocol(name); let contents = open_protocol(name);
let lex = Token::lexer(&contents); let lex = Token::lexer(&contents);
let mut tokens = vec![];
for x in lex { for x in lex {
match x { match x {
Ok(token) => println!("{:?}", token), Ok(token) => {
println!("{:?}", token);
tokens.push(token);
}
Err(err) => println!("{:?}", err), Err(err) => println!("{:?}", err),
} }
} }
build(tokens);
}
fn build(a: Vec<Token>) {
for toke in a {
println!("{:?}", toke);
}
} }
fn open_protocol(name: String) -> String { fn open_protocol(name: String) -> String {

View file

@ -2,17 +2,16 @@ pub enum ProtocolTypes {
Byte, Byte,
} }
pub struct Decorator { pub struct Protocol {}
pub name: String, impl Protocol {
pub value: Option<String>, pub fn is_empty(&self) -> bool {
} true
}
pub struct Protocol { pub fn validate_data(&self, data: Vec<u8>) -> bool {
pub name: String, if !data.is_empty() && self.is_empty() {
pub decorators: Vec<Decorator>, return false;
} }
true
pub struct IDLEnum { }
pub name: String,
pub accepted_values: Vec<(String, u64)>,
} }