forked from AbleOS/ableos
Compare commits
No commits in common. "39f7d5aba4a7ba8ad7a281471d6859fb6f9bbc2a" and "f9451e3d7ddd8e1d814acdb5814ad3698b67215b" have entirely different histories.
39f7d5aba4
...
f9451e3d7d
|
@ -22,8 +22,6 @@ enum Token {
|
||||||
// Tokens can be literal strings, of any length.
|
// Tokens can be literal strings, of any length.
|
||||||
#[token("type")]
|
#[token("type")]
|
||||||
Type,
|
Type,
|
||||||
#[token("fn", priority = 5)]
|
|
||||||
Fn,
|
|
||||||
|
|
||||||
#[token("enum")]
|
#[token("enum")]
|
||||||
Enum,
|
Enum,
|
||||||
|
@ -58,7 +56,7 @@ enum Token {
|
||||||
#[token("->")]
|
#[token("->")]
|
||||||
RArrow,
|
RArrow,
|
||||||
|
|
||||||
#[regex("[a-zA-Z_][a-zA-Z_1234567890]+", |lex|{lex.slice().to_string()})]
|
#[regex("[a-zA-Z_]+", |lex|{lex.slice().to_string()})]
|
||||||
Identifier(String),
|
Identifier(String),
|
||||||
|
|
||||||
#[regex("[1234567890]+", |lex|{lex.slice().parse::<u64>().unwrap()})]
|
#[regex("[1234567890]+", |lex|{lex.slice().parse::<u64>().unwrap()})]
|
||||||
|
@ -88,6 +86,9 @@ pub fn build_idl(name: String) {
|
||||||
println!("{:#?}", parse(tokens));
|
println!("{:#?}", parse(tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build(a: Vec<Token>) {
|
||||||
|
}
|
||||||
|
|
||||||
fn open_protocol(name: String) -> String {
|
fn open_protocol(name: String) -> String {
|
||||||
let path = format!("sysdata/idl/{}/src/protocol.aldi", name);
|
let path = format!("sysdata/idl/{}/src/protocol.aldi", name);
|
||||||
let mut file = std::fs::File::open(path).unwrap();
|
let mut file = std::fs::File::open(path).unwrap();
|
||||||
|
|
|
@ -9,7 +9,7 @@ enum Declaration{
|
||||||
EnumDeclaration(EnumDeclaration),
|
EnumDeclaration(EnumDeclaration),
|
||||||
StructDeclaration(StructDeclaration),
|
StructDeclaration(StructDeclaration),
|
||||||
TypeDeclaration(TypeDeclaration),
|
TypeDeclaration(TypeDeclaration),
|
||||||
ProtocolDeclaration(ProtocolDeclaration),
|
ProtocolDeclaration,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct StructDeclaration {
|
struct StructDeclaration {
|
||||||
|
@ -38,19 +38,6 @@ struct EnumMember {
|
||||||
number: u64,
|
number: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
struct ProtocolDeclaration{
|
|
||||||
name : String,
|
|
||||||
interface : Vec<FuncDeclaration>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
struct FuncDeclaration {
|
|
||||||
name : String,
|
|
||||||
arg_list : Vec<String>,
|
|
||||||
return_type : String,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Consume's a token that's expected. If the token that's consumed is not
|
/// Consume's a token that's expected. If the token that's consumed is not
|
||||||
/// the given expected token then panic
|
/// the given expected token then panic
|
||||||
|
@ -87,7 +74,6 @@ fn declaration(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<Declaration> {
|
||||||
Token::Enum => Some(enum_decl(tokens)),
|
Token::Enum => Some(enum_decl(tokens)),
|
||||||
Token::Struct => Some(struct_decl(tokens)),
|
Token::Struct => Some(struct_decl(tokens)),
|
||||||
Token::Type => Some(type_declaration(tokens)),
|
Token::Type => Some(type_declaration(tokens)),
|
||||||
Token::Protocol => Some(protocol_declaration(tokens)),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,61 +200,3 @@ fn parse_number(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<u64> {
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn protocol_declaration(tokens : &mut Peekable<Iter<'_, Token>>) -> Declaration {
|
|
||||||
consume(tokens, Token::Protocol);
|
|
||||||
let name = identifier(tokens).expect("Expected Identifier after `protocol`");
|
|
||||||
consume(tokens, Token::LBrace);
|
|
||||||
let mut interface = Vec::new();
|
|
||||||
match tokens.peek().expect("Unexpected EOF after LBrace") {
|
|
||||||
Token::RBrace => {},
|
|
||||||
_ => {
|
|
||||||
functions(tokens, &mut interface);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Declaration::ProtocolDeclaration(ProtocolDeclaration{name, interface})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn functions(tokens : &mut Peekable<Iter<'_, Token>>, interface : &mut Vec<FuncDeclaration>) {
|
|
||||||
loop {
|
|
||||||
match function(tokens) {
|
|
||||||
Some(x) => interface.push(x),
|
|
||||||
None => break,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn function(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<FuncDeclaration>{
|
|
||||||
if let Some(Token::Fn) = tokens.peek() {
|
|
||||||
consume(tokens, Token::Fn);
|
|
||||||
let name = identifier(tokens).expect("Expected Identifier after `fn`");
|
|
||||||
consume(tokens, Token::LParen);
|
|
||||||
let arg_list = arg_list(tokens);
|
|
||||||
consume(tokens, Token::RParen);
|
|
||||||
consume(tokens, Token::RArrow);
|
|
||||||
let return_type = identifier(tokens).expect("Expected return type after `->");
|
|
||||||
Some(FuncDeclaration{name, arg_list, return_type})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn arg_list(tokens : &mut Peekable<Iter<'_, Token>>) -> Vec<String> {
|
|
||||||
let mut result = Vec::new();
|
|
||||||
loop {
|
|
||||||
match identifier(tokens) {
|
|
||||||
None => break,
|
|
||||||
Some(i) =>{
|
|
||||||
result.push(i);
|
|
||||||
if **tokens.peek().expect("Unexpected EOF in argument list") == Token::Comma{
|
|
||||||
consume(tokens, Token::Comma);
|
|
||||||
match tokens.peek().expect("Unexpected EOF in argument list") {
|
|
||||||
Token::Identifier(_) => {},
|
|
||||||
_ => panic!("Unexpected symbol after Comma in argument list"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue