work
This commit is contained in:
+2
-25
@@ -1,13 +1,10 @@
|
||||
use crate::{
|
||||
io::{CompilerMsg, CompilerOutput},
|
||||
parser::{Cursor, nodes::*},
|
||||
};
|
||||
|
||||
mod ctx;
|
||||
mod dsp;
|
||||
pub use ctx::*;
|
||||
pub use dsp::*;
|
||||
|
||||
use crate::io::CompilerMsg;
|
||||
|
||||
pub trait Node: Sized {
|
||||
fn parse(ctx: &mut ParseCtx) -> Result<Self, CompilerMsg>;
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result;
|
||||
@@ -18,23 +15,3 @@ pub trait Node: Sized {
|
||||
self.dsp(DisplayCtx { indent: 0 })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_root(path: &str, output: &mut CompilerOutput) -> Option<Body> {
|
||||
let root_code = match std::fs::read_to_string(path) {
|
||||
Ok(code) => code,
|
||||
Err(err) => {
|
||||
output.error(format!("Failed to read input file: {err}"));
|
||||
return None;
|
||||
}
|
||||
};
|
||||
output.files.push(path.to_string());
|
||||
let mut ctx = ParseCtx::new(Cursor::new(&root_code, 0));
|
||||
let root = match ctx.parse() {
|
||||
Ok(v) => v,
|
||||
Err(msg) => {
|
||||
output.error(msg);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
Some(root)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user