work
This commit is contained in:
+2
-29
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user