From 33a4bf7d010029351fdb6e81bc31c02db646c704 Mon Sep 17 00:00:00 2001 From: mlokr Date: Fri, 19 Jul 2024 21:19:03 +0200 Subject: [PATCH] barbar --- hblang/src/codegen.rs | 7 +++---- hblang/src/lib.rs | 2 +- hblang/src/parser.rs | 23 ++++++++--------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 28553c6..7868fb5 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -3227,14 +3227,13 @@ mod tests { } } - let input = find_block(input, ident).trim(); - - parser::test::format(ident, input); + let input = find_block(input, ident); let mut module_map = Vec::new(); let mut last_start = 0; let mut last_module_name = "test"; for (i, m) in input.match_indices("// in module: ") { + parser::test::format(ident, input[last_start..i].trim()); module_map.push((last_module_name, &input[last_start..i])); let (module_name, _) = input[i + m.len()..].split_once('\n').unwrap(); last_module_name = module_name; @@ -3253,7 +3252,7 @@ mod tests { let mut codegen = super::Codegen { files: module_map .iter() - .map(|&(path, content)| parser::Ast::new(path, content, &loader, false)) + .map(|&(path, content)| parser::Ast::new(path, content, &loader)) .collect(), ..Default::default() }; diff --git a/hblang/src/lib.rs b/hblang/src/lib.rs index 2c33ebf..7059548 100644 --- a/hblang/src/lib.rs +++ b/hblang/src/lib.rs @@ -424,7 +424,7 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result> { let mut file = std::fs::File::open(path)?; file.read_to_end(buffer)?; let src = std::str::from_utf8(buffer).map_err(InvalidFileData)?; - Ok(Ast::new(path, src, &loader, false)) + Ok(Ast::new(path, src, &loader)) }; let thread = || { diff --git a/hblang/src/parser.rs b/hblang/src/parser.rs index d3e24af..59fe5f8 100644 --- a/hblang/src/parser.rs +++ b/hblang/src/parser.rs @@ -70,16 +70,10 @@ pub struct Parser<'a, 'b> { trailing_sep: bool, idents: Vec, captured: Vec, - loose: bool, } impl<'a, 'b> Parser<'a, 'b> { - pub fn new( - arena: &'b Arena<'a>, - symbols: &'b mut Symbols, - loader: Loader<'b>, - loose: bool, - ) -> Self { + pub fn new(arena: &'b Arena<'a>, symbols: &'b mut Symbols, loader: Loader<'b>) -> Self { let mut lexer = Lexer::new(""); Self { loader, @@ -92,7 +86,6 @@ impl<'a, 'b> Parser<'a, 'b> { trailing_sep: false, idents: Vec::new(), captured: Vec::new(), - loose, } } @@ -220,7 +213,7 @@ impl<'a, 'b> Parser<'a, 'b> { } let index = self.idents.binary_search_by_key(&id, |s| s.ident).expect("fck up"); - if std::mem::replace(&mut self.idents[index].declared, true) && !self.loose { + if std::mem::replace(&mut self.idents[index].declared, true) { self.report_pos( pos, format_args!("redeclaration of identifier: {}", self.lexer.slice(ident::range(id))), @@ -1084,10 +1077,10 @@ impl AstInner<[Symbol]> { .0 } - fn new(content: &str, path: &str, loader: Loader, loose: bool) -> NonNull { + fn new(content: &str, path: &str, loader: Loader) -> NonNull { let arena = Arena::default(); let mut syms = Vec::new(); - let mut parser = Parser::new(&arena, &mut syms, loader, loose); + let mut parser = Parser::new(&arena, &mut syms, loader); let exprs = parser.file(content, path) as *const [Expr<'static>]; syms.sort_unstable_by_key(|s| s.name); @@ -1119,8 +1112,8 @@ impl AstInner<[Symbol]> { pub struct Ast(NonNull>); impl Ast { - pub fn new(path: &str, content: &str, loader: Loader, loose: bool) -> Self { - Self(AstInner::new(content, path, loader, loose)) + pub fn new(path: &str, content: &str, loader: Loader) -> Self { + Self(AstInner::new(content, path, loader)) } pub fn exprs(&self) -> &[Expr] { @@ -1150,7 +1143,7 @@ impl std::fmt::Display for Ast { impl Default for Ast { fn default() -> Self { - Self(AstInner::new("", "", &no_loader, false)) + Self(AstInner::new("", "", &no_loader)) } } @@ -1326,7 +1319,7 @@ impl Drop for ArenaChunk { #[cfg(test)] pub mod test { pub fn format(ident: &str, input: &str) { - let ast = super::Ast::new(ident, input, &|_, _| Ok(0), true); + let ast = super::Ast::new(ident, input, &|_, _| Ok(0)); let mut output = Vec::new(); crate::format_to(&ast, input, &mut output).unwrap();