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 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
enum Token {
// Tokens can be literal strings, of any length.
@ -40,25 +43,36 @@ enum Token {
#[regex("[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
Text(String),
#[regex("[1234567890]+")]
Number,
#[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]+\)"#, |lex|{lex.slice().to_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),
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 {

View file

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