forked from AbleOS/ableos
Brought parser back completely from the dead
This commit is contained in:
parent
d0d6f0475e
commit
0e5d5f7de7
|
@ -88,9 +88,9 @@ fn declaration(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<Declaration> {
|
||||||
None => None,
|
None => None,
|
||||||
Some(tok) => match tok {
|
Some(tok) => match tok {
|
||||||
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)),
|
Token::Protocol(_) => Some(protocol_declaration(tokens)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,58 +141,58 @@ fn enum_member(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<EnumMember> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// fn struct_decl(tokens : &mut Peekable<Iter<'_, Token>>) -> Declaration {
|
fn struct_decl(tokens : &mut Peekable<Iter<'_, Token>>) -> Declaration {
|
||||||
// consume(tokens, Token::Struct);
|
consume!(tokens, Token::Struct);
|
||||||
// let name = identifier(tokens).expect("Expected Identifier after `struct`");
|
let name = identifier(tokens).expect("Expected Identifier after `struct`");
|
||||||
// consume(tokens, Token::LBrace);
|
consume!(tokens, Token::LBrace);
|
||||||
// let mut members = Vec::new();
|
let mut members = Vec::new();
|
||||||
//
|
|
||||||
// match tokens.peek().expect("Unexpected EOF after LBrace") {
|
match tokens.peek().expect("Unexpected EOF after LBrace") {
|
||||||
// Token::RBrace => {}, // skip checking for struct_members if empty
|
Token::RBrace(_) => {}, // skip checking for struct_members if empty
|
||||||
// _ => {
|
_ => {
|
||||||
// struct_members(tokens, &mut members);
|
struct_members(tokens, &mut members);
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// consume(tokens, Token::RBrace);
|
consume!(tokens, Token::RBrace);
|
||||||
//
|
|
||||||
// Declaration::StructDeclaration(StructDeclaration{name, members})
|
Declaration::StructDeclaration(StructDeclaration{name, members})
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// fn struct_members(tokens : &mut Peekable<Iter<'_, Token>>, members: &mut Vec<StructMember>) {
|
fn struct_members(tokens : &mut Peekable<Iter<'_, Token>>, members: &mut Vec<StructMember>) {
|
||||||
// members.push(struct_member(tokens).unwrap());
|
members.push(struct_member(tokens).unwrap());
|
||||||
// loop {
|
loop {
|
||||||
// match tokens.peek().expect("Unexpected EOF inside struct declaration") {
|
match tokens.peek().expect("Unexpected EOF inside struct declaration") {
|
||||||
// Token::Comma => {
|
Token::Comma(_) => {
|
||||||
// consume(tokens, Token::Comma);
|
consume!(tokens, Token::Comma);
|
||||||
// if let Some(member) = struct_member(tokens) {
|
if let Some(member) = struct_member(tokens) {
|
||||||
// members.push(member);
|
members.push(member);
|
||||||
// } else {
|
} else {
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// _ => {},
|
_ => {},
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// fn struct_member(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<StructMember> {
|
fn struct_member(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<StructMember> {
|
||||||
// let name = identifier(tokens);
|
let name = identifier(tokens);
|
||||||
// if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
// consume(tokens, Token::Colon);
|
consume!(tokens, Token::Colon);
|
||||||
// let type_name = identifier(tokens).expect("Expected Type after Colon");
|
let type_name = identifier(tokens).expect("Expected Type after Colon");
|
||||||
// Some(StructMember{name, type_name})
|
Some(StructMember{name, type_name})
|
||||||
// } else {
|
} else {
|
||||||
// None
|
None
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
}
|
||||||
// fn type_declaration(tokens : &mut Peekable<Iter<'_, Token>>) -> Declaration {
|
fn type_declaration(tokens : &mut Peekable<Iter<'_, Token>>) -> Declaration {
|
||||||
// consume(tokens, Token::Type);
|
consume!(tokens, Token::Type);
|
||||||
// let name = identifier(tokens).expect("Expected Identifier after `type`");
|
let name = identifier(tokens).expect("Expected Identifier after `type`");
|
||||||
// let type_name = identifier(tokens).expect("Expected type after Identifier");
|
let type_name = identifier(tokens).expect("Expected type after Identifier");
|
||||||
// Declaration::TypeDeclaration(TypeDeclaration{name, type_name})
|
Declaration::TypeDeclaration(TypeDeclaration{name, type_name})
|
||||||
// }
|
}
|
||||||
fn identifier(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<String> {
|
fn identifier(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<String> {
|
||||||
let result = tokens.peek().map_or(None, |x| match x {
|
let result = tokens.peek().map_or(None, |x| match x {
|
||||||
Token::Identifier((_, _, s)) => {
|
Token::Identifier((_, _, s)) => {
|
||||||
|
@ -217,61 +217,61 @@ fn parse_number(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<u64> {
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// fn protocol_declaration(tokens : &mut Peekable<Iter<'_, Token>>) -> Declaration {
|
fn protocol_declaration(tokens : &mut Peekable<Iter<'_, Token>>) -> Declaration {
|
||||||
// consume(tokens, Token::Protocol);
|
consume!(tokens, Token::Protocol);
|
||||||
// let name = identifier(tokens).expect("Expected Identifier after `protocol`");
|
let name = identifier(tokens).expect("Expected Identifier after `protocol`");
|
||||||
// consume(tokens, Token::LBrace);
|
consume!(tokens, Token::LBrace);
|
||||||
// let mut interface = Vec::new();
|
let mut interface = Vec::new();
|
||||||
// match tokens.peek().expect("Unexpected EOF after LBrace") {
|
match tokens.peek().expect("Unexpected EOF after LBrace") {
|
||||||
// Token::RBrace => {},
|
Token::RBrace(_) => {},
|
||||||
// _ => {
|
_ => {
|
||||||
// functions(tokens, &mut interface);
|
functions(tokens, &mut interface);
|
||||||
// },
|
},
|
||||||
// };
|
};
|
||||||
// Declaration::ProtocolDeclaration(ProtocolDeclaration{name, interface})
|
Declaration::ProtocolDeclaration(ProtocolDeclaration{name, interface})
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// fn functions(tokens : &mut Peekable<Iter<'_, Token>>, interface : &mut Vec<FuncDeclaration>) {
|
fn functions(tokens : &mut Peekable<Iter<'_, Token>>, interface : &mut Vec<FuncDeclaration>) {
|
||||||
// loop {
|
loop {
|
||||||
// match function(tokens) {
|
match function(tokens) {
|
||||||
// Some(x) => interface.push(x),
|
Some(x) => interface.push(x),
|
||||||
// None => break,
|
None => break,
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// fn function(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<FuncDeclaration>{
|
fn function(tokens : &mut Peekable<Iter<'_, Token>>) -> Option<FuncDeclaration>{
|
||||||
// if let Some(Token::Fn) = tokens.peek() {
|
if let Some(Token::Fn(_)) = tokens.peek() {
|
||||||
// consume(tokens, Token::Fn);
|
consume!(tokens, Token::Fn);
|
||||||
// let name = identifier(tokens).expect("Expected Identifier after `fn`");
|
let name = identifier(tokens).expect("Expected Identifier after `fn`");
|
||||||
// consume(tokens, Token::LParen);
|
consume!(tokens, Token::LParen);
|
||||||
// let arg_list = arg_list(tokens);
|
let arg_list = arg_list(tokens);
|
||||||
// consume(tokens, Token::RParen);
|
consume!(tokens, Token::RParen);
|
||||||
// consume(tokens, Token::RArrow((1,1)));
|
consume!(tokens, Token::RArrow);
|
||||||
// let return_type = identifier(tokens).expect("Expected return type after `->");
|
let return_type = identifier(tokens).expect("Expected return type after `->");
|
||||||
// Some(FuncDeclaration{name, arg_list, return_type})
|
Some(FuncDeclaration{name, arg_list, return_type})
|
||||||
// } else {
|
} else {
|
||||||
// None
|
None
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// fn arg_list(tokens : &mut Peekable<Iter<'_, Token>>) -> Vec<String> {
|
fn arg_list(tokens : &mut Peekable<Iter<'_, Token>>) -> Vec<String> {
|
||||||
// let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
// loop {
|
loop {
|
||||||
// match identifier(tokens) {
|
match identifier(tokens) {
|
||||||
// None => break,
|
None => break,
|
||||||
// Some(i) =>{
|
Some(i) =>{
|
||||||
// result.push(i);
|
result.push(i);
|
||||||
// if **tokens.peek().expect("Unexpected EOF in argument list") == Token::Comma{
|
if let Token::Comma(_) = **tokens.peek().expect("Unexpected EOF in argument list"){
|
||||||
// consume(tokens, Token::Comma);
|
consume!(tokens, Token::Comma);
|
||||||
// match tokens.peek().expect("Unexpected EOF in argument list") {
|
match tokens.peek().expect("Unexpected EOF in argument list") {
|
||||||
// Token::Identifier(_) => {},
|
Token::Identifier(_) => {},
|
||||||
// _ => panic!("Unexpected symbol after Comma in argument list"),
|
_ => panic!("Unexpected symbol after Comma in argument list"),
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// result
|
result
|
||||||
// }
|
}
|
||||||
|
|
Loading…
Reference in a new issue