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; use logos::Logos;
#[derive(Logos, Debug, PartialEq)] #[derive(Logos, Debug, PartialEq)]
@ -7,14 +11,31 @@ enum Token {
#[token("protocol")] #[token("protocol")]
Protocol, Protocol,
#[token(".")] #[token("{")]
Period, LBrace,
// Or regular expressions. #[token("}")]
#[regex("[a-zA-Z]+")] RBrace,
Text,
#[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() { pub fn build_idl(name: String) {
let mut lex = Token::lexer("Create ridiculously fast Lexers."); 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 std::io::Write;
use idl::build_idl;
pub mod idl; pub mod idl;
pub enum Options { pub enum Options {
@ -7,7 +9,7 @@ pub enum Options {
New, New,
Run, Run,
} }
#[derive(PartialEq)] #[derive(PartialEq, Debug)]
pub enum DevelopmentType { pub enum DevelopmentType {
Program, Program,
Library, Library,
@ -24,7 +26,7 @@ fn main() {
match subcommand { match subcommand {
"build" => { "build" => {
let name = &args[1]; let name = &args.pop().unwrap();
build(name.to_string()) build(name.to_string())
} }
"new" => { "new" => {
@ -103,7 +105,20 @@ fn run() {
fn build(name: String) { fn build(name: String) {
println!("building {}", name); 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() { fn help() {
println!( println!(

View file

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