feat: Add support for module parsing.
This commit is contained in:
@@ -121,3 +121,8 @@ pub struct Parameter {
|
||||
pub name_span: Span,
|
||||
pub type_: Type,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Module {
|
||||
pub declarations: Vec<Declaration>,
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ pub mod token;
|
||||
fn main() {
|
||||
let mut parser = Parser::new(include_str!("../example/simple.bky"));
|
||||
|
||||
println!("{:#?}", parser.parse_declaration());
|
||||
println!("{:#?}", parser.parse_module());
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ impl<'src> Parser<'src> {
|
||||
self.peek().is_some_and(|tok| tok.kind == kind)
|
||||
}
|
||||
|
||||
fn at_eof(&mut self) -> bool {
|
||||
self.peek().is_none()
|
||||
}
|
||||
|
||||
fn consume(&mut self) -> Option<Token<'src>> {
|
||||
self.tokens.next()
|
||||
}
|
||||
@@ -56,6 +60,16 @@ impl<'src> Parser<'src> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_module(&mut self) -> ParserResult<Module> {
|
||||
let mut declarations = Vec::new();
|
||||
|
||||
while !self.at_eof() {
|
||||
declarations.push(self.parse_declaration()?);
|
||||
}
|
||||
|
||||
Ok(Module { declarations })
|
||||
}
|
||||
|
||||
pub fn parse_declaration(&mut self) -> ParserResult<Declaration> {
|
||||
let peek_tok = self.peek_no_eof()?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user