1
0
Fork 0
forked from AbleOS/ableos

IDL tokenization

This commit is contained in:
Able 2024-09-02 21:50:43 -05:00
parent 7426bf479f
commit 1855307cd9
5 changed files with 59 additions and 16 deletions

View file

@ -17,18 +17,47 @@ enum Token {
#[token("}")]
RBrace,
#[regex("[a-zA-Z]+", |lex|{lex.slice().to_string()})]
#[token("(")]
LParen,
#[token(")")]
RParen,
#[token(":")]
Colon,
#[token(";")]
SemiColon,
#[token(",")]
Comma,
#[token("=")]
Equal,
#[token("->")]
RArrow,
#[regex("[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
Text(String),
#[regex(r#"@[a-zA-Z]+\(?[a-zA-Z]+\)?"#, |lex|{lex.slice().to_string()})]
#[regex("[1234567890]+")]
Number,
#[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()})]
DecoratorOption(String),
}
pub fn build_idl(name: String) {
let contents = open_protocol(name);
let lex = Token::lexer(&contents);
for x in lex {
println!("{:?}", x.unwrap());
match x {
Ok(token) => println!("{:?}", token),
Err(err) => println!("{:?}", err),
}
}
}

View file

@ -12,11 +12,7 @@ pub struct Protocol {
pub decorators: Vec<Decorator>,
}
pub struct Field {
pub name: String,
pub ptype: ProtocolTypes,
}
pub struct Structure {
pub fields: Vec<Field>,
pub struct IDLEnum {
pub name: String,
pub accepted_values: Vec<(String, u64)>,
}

View file

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

View file

@ -0,0 +1,24 @@
@auto_increment
enum LogLevel {
Error = 0,
Warn,
Info,
Debug,
Trace,
}
@auto_increment
enum LogResult {
Err = 0,
Ok,
}
struct Log {
log_level: LogLevel,
}
@visibility(public)
protocol Log {
fn log(Log) -> LogResult;
fn flush() -> LogResult;
}