This commit is contained in:
2026-04-11 03:50:43 -04:00
parent 29316e6353
commit 229b026573
16 changed files with 266 additions and 136 deletions
+2 -29
View File
@@ -1,6 +1,6 @@
use crate::{
io::{CompilerOutput, Span},
parser::{Cursor, Lit, nodes::*},
parser::{Cursor, nodes::*},
};
mod id;
@@ -8,16 +8,8 @@ mod parse;
pub use id::*;
pub use parse::*;
def_nodes! {
exprs: Expr,
idents: Ident,
statements: Statement,
blocks: Block,
lits: Lit,
}
impl Nodes {
pub fn parse_root(path: &str, output: &mut CompilerOutput) -> Option<(Self, Id<Block>)> {
pub fn parse_root(path: &str, output: &mut CompilerOutput) -> Option<(Self, Id<Module>)> {
let root_code = match std::fs::read_to_string(path) {
Ok(code) => code,
Err(err) => {
@@ -66,22 +58,3 @@ pub trait Node: Sized {
fn vec(nodes: &Nodes) -> &NodeVec<Self>;
fn vec_mut(nodes: &mut Nodes) -> &mut NodeVec<Self>;
}
macro_rules! def_nodes {
{$($field:ident: $ty:ident,)*} => {
#[derive(Default)]
pub struct Nodes {
$($field: NodeVec<$ty>,)*
}
$(impl Node for $ty {
fn vec(nodes: &Nodes) -> &NodeVec<Self> {
&nodes.$field
}
fn vec_mut(nodes: &mut Nodes) -> &mut NodeVec<Self> {
&mut nodes.$field
}
})*
};
}
use def_nodes;