error system now works for multiple functions
This commit is contained in:
parent
414b740ebc
commit
867799fec3
4 changed files with 59 additions and 41 deletions
|
@ -169,47 +169,52 @@ fn get_sorrunding_lines(file: &String, line: usize) -> (String, String, String)
|
|||
pub fn print_error(error: &ASLError, ctx: &Context) {
|
||||
let mut out = String::new();
|
||||
out.push_str(&convert_types_to_string(&error.typ));
|
||||
if error.message.len() > 0 {
|
||||
if error.message.len() < 1 {
|
||||
out.push_str(&convert_subtypes_to_string(&error.subtype));
|
||||
} else {
|
||||
out.push_str(&error.message);
|
||||
}
|
||||
out.push_str(" at position ");
|
||||
|
||||
let (line, column) = get_exact_pos(&ctx.raw_file, error.position);
|
||||
out.push_str(&ctx.file);
|
||||
out.push_str(":");
|
||||
out.push_str(&line.to_string());
|
||||
out.push_str(":");
|
||||
out.push_str(&column.to_string());
|
||||
|
||||
out.push_str("\n");
|
||||
let (before, current, after) = get_sorrunding_lines(&ctx.raw_file, line);
|
||||
if line > 1 {
|
||||
out.push_str(&(line-1).to_string());
|
||||
out.push_str(" | ");
|
||||
} else {
|
||||
out.push_str(" | ");
|
||||
}
|
||||
out.push_str(&before);
|
||||
out.push_str("\n");
|
||||
out.push_str(&line.to_string());
|
||||
out.push_str(" | ");
|
||||
out.push_str(¤t);
|
||||
|
||||
out.push_str("\n");
|
||||
out.push_str(" ");
|
||||
out.push_str(&" ".repeat(column - 1));
|
||||
out.push_str("^ ");
|
||||
out.push_str(&error.message);
|
||||
if ctx.known {
|
||||
out.push_str(" at position ");
|
||||
|
||||
out.push_str("\n");
|
||||
out.push_str(&(line+1).to_string());
|
||||
out.push_str(" | ");
|
||||
out.push_str(&after);
|
||||
let (line, column) = get_exact_pos(&ctx.raw_file, error.position);
|
||||
out.push_str(&ctx.file);
|
||||
out.push_str(":");
|
||||
out.push_str(&line.to_string());
|
||||
out.push_str(":");
|
||||
out.push_str(&column.to_string());
|
||||
|
||||
out.push_str("\n");
|
||||
let (before, current, after) = get_sorrunding_lines(&ctx.raw_file, line);
|
||||
if line > 1 {
|
||||
out.push_str(&(line-1).to_string());
|
||||
out.push_str(" | ");
|
||||
} else {
|
||||
out.push_str(" | ");
|
||||
}
|
||||
out.push_str(&before);
|
||||
out.push_str("\n");
|
||||
out.push_str(&line.to_string());
|
||||
out.push_str(" | ");
|
||||
out.push_str(¤t);
|
||||
|
||||
out.push_str("\n");
|
||||
out.push_str(" ");
|
||||
out.push_str(&" ".repeat(column - 1));
|
||||
out.push_str("^ ");
|
||||
out.push_str(&error.message);
|
||||
|
||||
out.push_str("\n");
|
||||
out.push_str(&(line+1).to_string());
|
||||
out.push_str(" | ");
|
||||
out.push_str(&after);
|
||||
}
|
||||
|
||||
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