actually compiles and does stuff now
This commit is contained in:
@@ -1,79 +1,70 @@
|
||||
use super::{
|
||||
AsmFunction, Function, Impl, Keyword, Node, Parsable, ParseResult, ParserMsg, ParserOutput,
|
||||
Struct, Symbol, Token, TokenCursor, Trait,
|
||||
PFunction, PImpl, Keyword, Node, Parsable, ParseResult, ParserCtx, ParserMsg,
|
||||
PStruct, Symbol, Token, PTrait,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub struct Module {
|
||||
pub traits: Vec<Node<Trait>>,
|
||||
pub structs: Vec<Node<Struct>>,
|
||||
pub functions: Vec<Node<Function>>,
|
||||
pub asm_fns: Vec<Node<AsmFunction>>,
|
||||
pub impls: Vec<Node<Impl>>,
|
||||
pub struct PModule {
|
||||
pub traits: Vec<Node<PTrait>>,
|
||||
pub structs: Vec<Node<PStruct>>,
|
||||
pub functions: Vec<Node<PFunction>>,
|
||||
pub impls: Vec<Node<PImpl>>,
|
||||
}
|
||||
|
||||
impl Parsable for Module {
|
||||
fn parse(cursor: &mut TokenCursor, errors: &mut ParserOutput) -> ParseResult<Self> {
|
||||
impl Parsable for PModule {
|
||||
fn parse(ctx: &mut ParserCtx) -> ParseResult<Self> {
|
||||
let mut functions = Vec::new();
|
||||
let mut structs = Vec::new();
|
||||
let mut traits = Vec::new();
|
||||
let mut impls = Vec::new();
|
||||
let mut asm_fns = Vec::new();
|
||||
loop {
|
||||
let Some(next) = cursor.peek() else {
|
||||
let Some(next) = ctx.peek() else {
|
||||
break;
|
||||
};
|
||||
if let Token::Keyword(kw) = next.token {
|
||||
match kw {
|
||||
Keyword::Fn => {
|
||||
let res = Node::parse(cursor, errors);
|
||||
let res = ctx.parse();
|
||||
functions.push(res.node);
|
||||
if res.recover {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Keyword::Struct => {
|
||||
let res = Node::parse(cursor, errors);
|
||||
let res = ctx.parse();
|
||||
structs.push(res.node);
|
||||
if res.recover {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Keyword::Trait => {
|
||||
let res = Node::parse(cursor, errors);
|
||||
let res = ctx.parse();
|
||||
traits.push(res.node);
|
||||
if res.recover {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Keyword::Impl => {
|
||||
let res = Node::parse(cursor, errors);
|
||||
let res = ctx.parse();
|
||||
impls.push(res.node);
|
||||
if res.recover {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Keyword::Asm => {
|
||||
let res = Node::parse(cursor, errors);
|
||||
asm_fns.push(res.node);
|
||||
if res.recover {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
errors.err(ParserMsg::unexpected_token(next, "a definition"));
|
||||
cursor.next();
|
||||
ctx.err(ParserMsg::unexpected_token(next, "a definition"));
|
||||
ctx.next();
|
||||
}
|
||||
}
|
||||
} else if next.is_symbol(Symbol::Semicolon) {
|
||||
errors.hint(ParserMsg::from_instances(
|
||||
ctx.hint(ParserMsg::from_instances(
|
||||
&[next],
|
||||
"unneeded semicolon".to_string(),
|
||||
));
|
||||
cursor.next();
|
||||
ctx.next();
|
||||
} else {
|
||||
errors.err(ParserMsg::unexpected_token(next, "a definition"));
|
||||
cursor.next();
|
||||
ctx.err(ParserMsg::unexpected_token(next, "a definition"));
|
||||
ctx.next();
|
||||
}
|
||||
}
|
||||
ParseResult::Ok(Self {
|
||||
@@ -81,12 +72,11 @@ impl Parsable for Module {
|
||||
structs,
|
||||
traits,
|
||||
impls,
|
||||
asm_fns,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Module {
|
||||
impl Debug for PModule {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
for st in &self.structs {
|
||||
st.fmt(f)?;
|
||||
@@ -104,10 +94,6 @@ impl Debug for Module {
|
||||
func.fmt(f)?;
|
||||
writeln!(f)?;
|
||||
}
|
||||
for func in &self.asm_fns {
|
||||
func.fmt(f)?;
|
||||
writeln!(f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user