refactor: changes
This commit is contained in:
parent
15030635fb
commit
9857863220
@ -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<char>) -> 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<char>) -> String {
|
||||
|
@ -88,7 +88,7 @@ pub fn get_tokens(input: &String) -> Result<Vec<Token>, MistiError> {
|
||||
current_pos = next_pos;
|
||||
}
|
||||
LexResult::Err(error_info) => {
|
||||
return Err(MistiError::Lex(error_info));
|
||||
return Err(error_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)?;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -16,7 +16,7 @@ use self::parseable::{Parseable, ParsingError, ParsingResult};
|
||||
pub fn build_ast<'a>(tokens: &'a Vec<Token>) -> Result<ModuleAST, MistiError> {
|
||||
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")
|
||||
|
Loading…
Reference in New Issue
Block a user