added imports
This commit is contained in:
parent
ce93fb10d4
commit
b4f930d1c5
8 changed files with 91 additions and 14 deletions
|
@ -6,6 +6,7 @@ pub enum ErrorType {
|
|||
TypeError,
|
||||
MathError,
|
||||
MachineError,
|
||||
IOError,
|
||||
}
|
||||
|
||||
pub enum ErrorSubType {
|
||||
|
@ -36,6 +37,8 @@ pub enum ErrorSubType {
|
|||
DivisionByZero,
|
||||
//Type errors
|
||||
WrongType,
|
||||
//IO errors
|
||||
FileError
|
||||
}
|
||||
|
||||
pub struct ASLError {
|
||||
|
@ -53,6 +56,7 @@ fn convert_types_to_string(typ: &ErrorType) -> String {
|
|||
ErrorType::MathError => String::from("Math Error: "),
|
||||
ErrorType::SemanticError => String::from("Semantic Error: "),
|
||||
ErrorType::MachineError => String::from("Machine Error: "),
|
||||
ErrorType::IOError => String::from("IO Error: "),
|
||||
}
|
||||
}
|
||||
fn convert_types_to_short(typ: &ErrorType) -> String {
|
||||
|
@ -62,6 +66,7 @@ fn convert_types_to_short(typ: &ErrorType) -> String {
|
|||
ErrorType::MathError => String::from("MT:"),
|
||||
ErrorType::SemanticError => String::from("SM:"),
|
||||
ErrorType::MachineError => String::from("MC:"),
|
||||
ErrorType::IOError => String::from("IO:"),
|
||||
}
|
||||
}
|
||||
fn convert_subtypes_to_string(stype: &ErrorSubType) -> String {
|
||||
|
@ -88,6 +93,7 @@ fn convert_subtypes_to_string(stype: &ErrorSubType) -> String {
|
|||
ErrorSubType::DivisionByZero => String::from("Division by zero"),
|
||||
ErrorSubType::WrongType => String::from("Wrong type"),
|
||||
ErrorSubType::TooManyArguments => String::from("Too many arguments"),
|
||||
ErrorSubType::FileError => String::from("File error"),
|
||||
}
|
||||
}
|
||||
fn convert_subtypes_to_short(stype: &ErrorSubType) -> String {
|
||||
|
@ -114,6 +120,7 @@ fn convert_subtypes_to_short(stype: &ErrorSubType) -> String {
|
|||
ErrorSubType::DivisionByZero => String::from("DZ:"),
|
||||
ErrorSubType::WrongType => String::from("WT:"),
|
||||
ErrorSubType::TooManyArguments => String::from("TA:"),
|
||||
ErrorSubType::FileError => String::from("FE:"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,6 +140,9 @@ pub fn create_error(message: &str, position: usize, typ: ErrorType, stype: Error
|
|||
fn get_exact_pos(file: &String, pos: usize) -> (usize, usize) {
|
||||
let mut line = 1;
|
||||
let mut column = 1;
|
||||
if pos < 1 {
|
||||
return (line, column);
|
||||
}
|
||||
for (i, c) in file.chars().enumerate() {
|
||||
if i == pos-1 {
|
||||
return (line, column);
|
||||
|
@ -203,7 +213,11 @@ pub fn print_error(error: &ASLError, ctx: &Context) {
|
|||
out.push_str(" ");
|
||||
out.push_str(&" ".repeat(column - 1));
|
||||
out.push_str("^ ");
|
||||
out.push_str(&error.message);
|
||||
if error.message.len() < 1 {
|
||||
out.push_str(&convert_subtypes_to_string(&error.subtype));
|
||||
} else {
|
||||
out.push_str(&error.message);
|
||||
}
|
||||
|
||||
out.push_str("\n");
|
||||
out.push_str(&(line+1).to_string());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue