From 0594b99a59aa1f86e7d24e0ac2bd043e93570db7 Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 3 Sep 2024 03:34:29 -0500 Subject: [PATCH] cleanup --- dev/src/idl/mod.rs | 26 ++++++++++++++++++++------ dev/src/idl/protocol.rs | 23 +++++++++++------------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/dev/src/idl/mod.rs b/dev/src/idl/mod.rs index 438ac88..212416c 100644 --- a/dev/src/idl/mod.rs +++ b/dev/src/idl/mod.rs @@ -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::().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) { + for toke in a { + println!("{:?}", toke); + } } fn open_protocol(name: String) -> String { diff --git a/dev/src/idl/protocol.rs b/dev/src/idl/protocol.rs index 1d0fa14..623a2f7 100644 --- a/dev/src/idl/protocol.rs +++ b/dev/src/idl/protocol.rs @@ -2,17 +2,16 @@ pub enum ProtocolTypes { Byte, } -pub struct Decorator { - pub name: String, - pub value: Option, -} +pub struct Protocol {} +impl Protocol { + pub fn is_empty(&self) -> bool { + true + } -pub struct Protocol { - pub name: String, - pub decorators: Vec, -} - -pub struct IDLEnum { - pub name: String, - pub accepted_values: Vec<(String, u64)>, + pub fn validate_data(&self, data: Vec) -> bool { + if !data.is_empty() && self.is_empty() { + return false; + } + true + } }