diff --git a/src/error_handling/mod.rs b/src/error_handling/mod.rs index 127bd97..c7f24d9 100644 --- a/src/error_handling/mod.rs +++ b/src/error_handling/mod.rs @@ -3,8 +3,6 @@ use std::ops::Range; use ariadne::{Label, Report, ReportKind, Source}; use serde::Serialize; -use self::semantic_error::SemanticError; - pub mod semantic_error; mod utils; @@ -32,30 +30,16 @@ pub struct ErrorLabel { pub end: usize, } +pub type MistiError = ErrorContainer; + +/* #[derive(Serialize, Debug)] pub enum MistiError { Lex(ErrorContainer), Syntax(ErrorContainer), Semantic(ErrorContainer), } - -impl PrintableError for MistiError { - fn get_error_str(&self, chars: &Vec) -> String { - match self { - Self::Lex(_) => panic!("REMOVED: manually generating an error message"), - Self::Syntax(err) => err.get_error_str(chars), - Self::Semantic(err) => err.get_error_str(chars), - } - } - - fn print_ariadne(&self, source: &String) { - match self { - Self::Lex(err) => err.print_ariadne(source), - Self::Syntax(err) => err.print_ariadne(source), - Self::Semantic(err) => err.print_ariadne(source), - } - } -} +*/ impl PrintableError for ErrorContainer { fn get_error_str(&self, _: &Vec) -> String { diff --git a/src/lexic/mod.rs b/src/lexic/mod.rs index 20c3d4e..03db07f 100755 --- a/src/lexic/mod.rs +++ b/src/lexic/mod.rs @@ -88,7 +88,7 @@ pub fn get_tokens(input: &String) -> Result, MistiError> { current_pos = next_pos; } LexResult::Err(error_info) => { - return Err(MistiError::Lex(error_info)); + return Err(error_info); } } } diff --git a/src/semantic/checks/binding.rs b/src/semantic/checks/binding.rs index dfeef7b..44342fc 100644 --- a/src/semantic/checks/binding.rs +++ b/src/semantic/checks/binding.rs @@ -1,8 +1,5 @@ use crate::{ - error_handling::{ - error_messages::SEMANTIC_DUPLICATED_REFERENCE, semantic_error::SemanticError, - ErrorContainer, ErrorLabel, MistiError, - }, + error_handling::{error_messages::SEMANTIC_DUPLICATED_REFERENCE, ErrorContainer, ErrorLabel}, semantic::{ impls::SemanticCheck, types::{Type, Typed}, @@ -32,7 +29,7 @@ impl SemanticCheck for VariableBinding<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } // This gets the datatype of the assigned expression, @@ -62,7 +59,7 @@ impl SemanticCheck for VariableBinding<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } scope.insert(binding_name.clone(), datatype); diff --git a/src/semantic/checks/conditional.rs b/src/semantic/checks/conditional.rs index dfb18ee..d386c65 100644 --- a/src/semantic/checks/conditional.rs +++ b/src/semantic/checks/conditional.rs @@ -1,7 +1,6 @@ use crate::{ error_handling::{ - error_messages::SEMANTIC_MISMATCHED_TYPES, semantic_error::SemanticError, ErrorContainer, - ErrorLabel, MistiError, + error_messages::SEMANTIC_MISMATCHED_TYPES, ErrorContainer, ErrorLabel, MistiError, }, semantic::{ impls::SemanticCheck, @@ -35,7 +34,7 @@ impl SemanticCheck for Conditional<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } // Check if block @@ -63,7 +62,7 @@ impl SemanticCheck for Conditional<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } else_if_member.body.check_semantics(scope)?; diff --git a/src/semantic/checks/expression.rs b/src/semantic/checks/expression.rs index 4c113ab..4be0182 100644 --- a/src/semantic/checks/expression.rs +++ b/src/semantic/checks/expression.rs @@ -44,7 +44,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } // Check that each argument matches the required datatype @@ -71,7 +71,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } } @@ -94,7 +94,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } } } @@ -129,7 +129,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } } ("!", Type::Function(_, _)) => { @@ -147,7 +147,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } ("-", Type::Value(t)) => { if t == "Int" || t == "Float" { @@ -168,7 +168,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } } ("-", Type::Function(_, _)) => { @@ -186,7 +186,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } (op, _) => { // Compiler error: something that shouldn't be @@ -220,7 +220,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } }; @@ -253,7 +253,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } if !right_expr_type.is_value(&op_params[1]) { @@ -273,7 +273,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } // After all these checks, we are ok @@ -306,7 +306,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } let mut expressions = arr.exps.iter(); @@ -337,7 +337,7 @@ impl SemanticCheck for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } } diff --git a/src/semantic/checks/for_loop.rs b/src/semantic/checks/for_loop.rs index a0ee116..6b4cd87 100644 --- a/src/semantic/checks/for_loop.rs +++ b/src/semantic/checks/for_loop.rs @@ -44,7 +44,7 @@ impl SemanticCheck for ForLoop<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } }; let item_type = &item_type[0]; diff --git a/src/semantic/checks/function_declaration.rs b/src/semantic/checks/function_declaration.rs index 2435f18..edd9c94 100644 --- a/src/semantic/checks/function_declaration.rs +++ b/src/semantic/checks/function_declaration.rs @@ -1,7 +1,5 @@ use crate::{ - error_handling::{ - error_messages::SEMANTIC_DUPLICATED_REFERENCE, ErrorContainer, ErrorLabel, MistiError, - }, + error_handling::{error_messages::SEMANTIC_DUPLICATED_REFERENCE, ErrorContainer, ErrorLabel}, semantic::{impls::SemanticCheck, symbol_table::SymbolTable, types::Type}, syntax::ast::FunctionDeclaration, }; @@ -32,7 +30,7 @@ impl SemanticCheck for FunctionDeclaration<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } // Create a new scope and use it in the function block diff --git a/src/semantic/checks/while_loop.rs b/src/semantic/checks/while_loop.rs index 9a8c8cf..4d2547d 100644 --- a/src/semantic/checks/while_loop.rs +++ b/src/semantic/checks/while_loop.rs @@ -34,7 +34,7 @@ impl SemanticCheck for WhileLoop<'_> { note: Some(String::from("THP does not have truthy/falsey values.")), help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } // TODO: Define scoping rules for while loops diff --git a/src/semantic/types/expression.rs b/src/semantic/types/expression.rs index 04c8479..e00d56a 100644 --- a/src/semantic/types/expression.rs +++ b/src/semantic/types/expression.rs @@ -37,7 +37,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } }; @@ -72,7 +72,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } None => { let label = ErrorLabel { @@ -89,7 +89,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } } } @@ -115,7 +115,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } }; @@ -135,7 +135,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } else { return Ok(Type::Value("Int".into())); } @@ -154,7 +154,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } else { return Ok(Type::Value("Bool".into())); } @@ -187,7 +187,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } Expression::Array(arr) => { // The first expression found determines the @@ -211,7 +211,7 @@ impl Typed for Expression<'_> { note: None, help: None, }; - return Err(MistiError::Semantic(econtainer)); + return Err(econtainer); } // Just get the first type and use it diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index a9c8420..e905f3b 100755 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -16,7 +16,7 @@ use self::parseable::{Parseable, ParsingError, ParsingResult}; pub fn build_ast<'a>(tokens: &'a Vec) -> Result { match ModuleAST::try_parse(tokens, 0) { Ok((module, _)) => Ok(module), - Err(ParsingError::Err(error)) => Err(MistiError::Syntax(error)), + Err(ParsingError::Err(error)) => Err(error), _ => { // This shouldn't happen. The module parser returns an error if it finds nothing to parse. unreachable!("Illegal state during parsing: The Module parse should always return a result or error")