From 9640a5b05b76329fec422380a68829b7a98f6af4 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Tue, 19 Oct 2021 18:22:34 -0700 Subject: [PATCH] Use vec of duplicate errors --- schala-lang/language/src/symbol_table/mod.rs | 33 +++++++------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/schala-lang/language/src/symbol_table/mod.rs b/schala-lang/language/src/symbol_table/mod.rs index 65ea33a..8c77f6a 100644 --- a/schala-lang/language/src/symbol_table/mod.rs +++ b/schala-lang/language/src/symbol_table/mod.rs @@ -134,7 +134,10 @@ impl SymbolTable { /// compilation process. pub fn process_ast(&mut self, ast: &ast::AST) -> Result<(), String> { - self.populate_name_tables(ast)?; + let errs = self.populate_name_tables(ast); + if !errs.is_empty() { + return Err(format!("{:?}", errs)); + } self.resolve_symbol_ids(ast)?; Ok(()) } @@ -211,14 +214,12 @@ impl SymbolTable { /// constants, functions, types, and modules defined within. This simultaneously /// checks for dupicate definitions (and returns errors if discovered), and sets /// up name tables that will be used by further parts of the compiler - fn populate_name_tables(&mut self, ast: &ast::AST) -> Result<(), String> { + fn populate_name_tables(&mut self, ast: &ast::AST) -> Vec { let mut scope_stack = vec![]; self.add_from_scope(ast.statements.as_ref(), &mut scope_stack) - .map_err(|err| format!("{:?}", err))?; - Ok(()) } - fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec) -> Result<(), Vec> { + fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec) -> Vec { let mut errors = vec![]; for statement in statements { @@ -245,19 +246,12 @@ impl SymbolTable { StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => { self.add_type_members(name, body, mutable, location, scope_stack) } - _ => Ok(()) + _ => vec![] }; - - if let Err(errs) = recursive_errs { - errors.extend(errs.into_iter()); - } + errors.extend(recursive_errs.into_iter()); } - if errors.is_empty() { - Ok(()) - } else { - Err(errors) - } + errors } fn add_single_statement(&mut self, kind: &StatementKind, location: Location, scope_stack: &Vec) -> Result<(), DuplicateName> { @@ -304,7 +298,7 @@ impl SymbolTable { Ok(()) } - fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec) -> Result<(), Vec> { + fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec) -> Vec { let mut errors = vec![]; let mut register = |fqsn: FQSN, spec: SymbolSpec| { @@ -378,11 +372,6 @@ impl SymbolTable { } scope_stack.pop(); - - if errors.is_empty() { - Ok(()) - } else { - Err(errors) - } + errors } }