prepare the error system for try/catch
This commit is contained in:
parent
1a98959be0
commit
3dd28cedd3
7 changed files with 146 additions and 118 deletions
|
@ -1,5 +1,6 @@
|
|||
use crate::Context;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ErrorType {
|
||||
SyntaxError,
|
||||
SemanticError,
|
||||
|
@ -9,6 +10,7 @@ pub enum ErrorType {
|
|||
IOError,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ErrorSubType {
|
||||
//Syntax errors
|
||||
UnexpectedEnd,
|
||||
|
@ -43,6 +45,7 @@ pub enum ErrorSubType {
|
|||
FileError
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ASLError {
|
||||
pub message: String,
|
||||
pub position: usize,
|
||||
|
@ -171,9 +174,11 @@ pub fn reverse_subtype_short(str: String) -> ErrorSubType {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_error(message: &str, position: usize, typ: ErrorType, stype: ErrorSubType) -> ASLError {
|
||||
pub fn create_error(message: &str, position: usize, typ: ErrorType, stype: ErrorSubType, ctx: &Context) -> ASLError {
|
||||
let mut code = convert_types_to_short(&typ);
|
||||
code.push_str(&convert_subtypes_to_short(&stype));
|
||||
code.push_str(ctx.c_funcid.to_string().as_str());
|
||||
code.push(':');
|
||||
code.push_str(&position.to_string());
|
||||
ASLError {
|
||||
message: String::from(message),
|
||||
|
@ -276,7 +281,5 @@ pub fn print_error(error: &ASLError, ctx: &Context) {
|
|||
out.push_str("\n");
|
||||
out.push_str("Error Code: ");
|
||||
out.push_str(&error.code);
|
||||
out.push_str(":");
|
||||
out.push_str(&ctx.c_funcid.to_string());
|
||||
println!("{}", out);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue