feat: wire up the parser in the main function
This commit is contained in:
@@ -48,7 +48,7 @@ impl<'src> Parser<'src> {
|
||||
}
|
||||
|
||||
/// Finish the parsing process returning the errors if any have occured.
|
||||
pub fn finish(self) -> Option<Vec<ParseError>> {
|
||||
pub fn errors(self) -> Option<Vec<ParseError>> {
|
||||
(!self.errors.is_empty()).then_some(self.errors)
|
||||
}
|
||||
|
||||
|
||||
+26
-1
@@ -1,5 +1,30 @@
|
||||
use std::{env::args, fs::read_to_string, process::exit};
|
||||
|
||||
use crate::frontend::parser::Parser;
|
||||
|
||||
pub mod frontend;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let Some(path) = args().nth(1) else {
|
||||
eprintln!("usage: compiler <file>");
|
||||
exit(1);
|
||||
};
|
||||
|
||||
let content = read_to_string(&path).unwrap_or_else(|err| {
|
||||
eprintln!("error: failed to read source file ({:?})", err);
|
||||
exit(1);
|
||||
});
|
||||
|
||||
let mut parser = Parser::new(&content);
|
||||
let module = parser.parse_module();
|
||||
|
||||
if let Some(errors) = parser.errors() {
|
||||
for error in errors {
|
||||
eprintln!("{:?}", error);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
println!("{:#?}", module);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user