This commit is contained in:
2026-04-18 00:16:03 -04:00
parent b3f77076d4
commit d864adfd05
12 changed files with 167 additions and 38 deletions
+2 -25
View File
@@ -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)
}