From 1a533eb788c914edb97eae9a7af972207f2876c7 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Thu, 6 Jun 2024 09:53:28 +0200 Subject: [PATCH] lang: smol module tree things and details --- crates/lang/src/ast.rs | 7 ------- crates/lang/src/ast/mod_tree.rs | 14 +++++++------- testfiles/hello.owo | 2 ++ testfiles/hello/meow.owo | 4 +++- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/crates/lang/src/ast.rs b/crates/lang/src/ast.rs index 6ff6b03..3bbb2f1 100644 --- a/crates/lang/src/ast.rs +++ b/crates/lang/src/ast.rs @@ -58,11 +58,4 @@ impl World { module_tree, }) } - - // fn parse_mod_tree(files: &mut HashMap) } - -// struct SourceFile { -// tree: SyntaxNode, -// items: Vec, -// } diff --git a/crates/lang/src/ast/mod_tree.rs b/crates/lang/src/ast/mod_tree.rs index 35df053..8cc373f 100644 --- a/crates/lang/src/ast/mod_tree.rs +++ b/crates/lang/src/ast/mod_tree.rs @@ -18,7 +18,7 @@ use super::{ }; pub struct ModuleTree { - modules: Rc>, + modules: Rc>>, } #[derive(Clone)] @@ -71,7 +71,7 @@ impl ModuleParsingContext { &self, node: &SyntaxNode, name: Option, - ) -> HashMap { + ) -> HashMap> { let mut ctx = self.clone(); if let Some(name) = name { ctx.push_cur_path(name) @@ -79,13 +79,13 @@ impl ModuleParsingContext { node.children() .filter_map(Mod::cast) .filter_map(|m| match Module::parse_mod(m, self.clone()) { - Ok(module) => Some((module.name(), module)), + Ok(module) => Some((module.name(), Rc::new(module))), Err(error) => { self.errors.borrow_mut().push(error); None } }) - .collect::>() + .collect::>>() } fn dissolve(self) -> (HashMap, Vec) { @@ -118,8 +118,8 @@ pub struct Module { path: Vec, name: String, kind: ModuleKind, - children: Rc>, - parent: Option>, + children: Rc>>, + parent: Option>, } impl Module { @@ -214,7 +214,7 @@ impl Module { } } -fn print_tree(name: &str, children: Rc>, level: u32) { +fn print_tree(name: &str, children: Rc>>, level: u32) { const INDENT_STR: &str = " "; for _ in 0..level { diff --git a/testfiles/hello.owo b/testfiles/hello.owo index d72460b..f2fe209 100644 --- a/testfiles/hello.owo +++ b/testfiles/hello.owo @@ -1 +1,3 @@ mod meow; + +def broken diff --git a/testfiles/hello/meow.owo b/testfiles/hello/meow.owo index 643c13a..3140a4a 100644 --- a/testfiles/hello/meow.owo +++ b/testfiles/hello/meow.owo @@ -1,2 +1,4 @@ mod mrawr {} -mod mrow {} +mod mrow { + def gay = ; +}