1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
Able 2024-08-30 12:31:45 -05:00
parent 6295a7118e
commit 7426bf479f
4 changed files with 72 additions and 10 deletions

View file

@ -1,3 +1,7 @@
pub mod protocol;
use std::io::Read;
use logos::Logos;
#[derive(Logos, Debug, PartialEq)]
@ -7,14 +11,31 @@ enum Token {
#[token("protocol")]
Protocol,
#[token(".")]
Period,
#[token("{")]
LBrace,
// Or regular expressions.
#[regex("[a-zA-Z]+")]
Text,
#[token("}")]
RBrace,
#[regex("[a-zA-Z]+", |lex|{lex.slice().to_string()})]
Text(String),
#[regex(r#"@[a-zA-Z]+\(?[a-zA-Z]+\)?"#, |lex|{lex.slice().to_string()})]
Decorator(String),
}
pub fn main() {
let mut lex = Token::lexer("Create ridiculously fast Lexers.");
pub fn build_idl(name: String) {
let contents = open_protocol(name);
let lex = Token::lexer(&contents);
for x in lex {
println!("{:?}", x.unwrap());
}
}
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
}

22
dev/src/idl/protocol.rs Normal file
View file

@ -0,0 +1,22 @@
pub enum ProtocolTypes {
Byte,
}
pub struct Decorator {
pub name: String,
pub value: Option<String>,
}
pub struct Protocol {
pub name: String,
pub decorators: Vec<Decorator>,
}
pub struct Field {
pub name: String,
pub ptype: ProtocolTypes,
}
pub struct Structure {
pub fields: Vec<Field>,
}

View file

@ -1,4 +1,6 @@
use std::io::Write;
use idl::build_idl;
pub mod idl;
pub enum Options {
@ -7,7 +9,7 @@ pub enum Options {
New,
Run,
}
#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
pub enum DevelopmentType {
Program,
Library,
@ -24,7 +26,7 @@ fn main() {
match subcommand {
"build" => {
let name = &args[1];
let name = &args.pop().unwrap();
build(name.to_string())
}
"new" => {
@ -103,7 +105,20 @@ fn run() {
fn build(name: String) {
println!("building {}", name);
let mut a = name.split("/");
let dev_type = a.next().unwrap();
let name = a.next().unwrap().to_string();
match dev_type {
"programs" => build_program(name),
"idl" => build_idl(name),
_ => {
panic!()
}
}
}
pub fn build_program(name: String) {}
pub fn build_library(name: String) {}
fn help() {
println!(

View file

@ -1,2 +1,6 @@
@visibility(public)
protocol abc {
}