Errors now use Location instead of line numbers
This commit is contained in:
@@ -2,12 +2,42 @@ use std::fmt::{Display, Formatter};
|
||||
|
||||
use vcore::opcodes::InvalidMnemonic;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Location {
|
||||
pub line_num: usize,
|
||||
pub file: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum ParseError {
|
||||
LineParseFailure,
|
||||
InvalidInstruction(String),
|
||||
}
|
||||
|
||||
impl Display for Location {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}:{}", self.file, self.line_num)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Location {
|
||||
fn default() -> Self {
|
||||
Location {
|
||||
line_num: 0,
|
||||
file: "<none>".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for Location {
|
||||
fn from(line: usize) -> Self {
|
||||
Self {
|
||||
line_num: line,
|
||||
file: "<none>".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<InvalidMnemonic<'a>> for ParseError {
|
||||
fn from(err: InvalidMnemonic<'a>) -> Self {
|
||||
Self::InvalidInstruction(err.0.into())
|
||||
@@ -26,43 +56,43 @@ impl Display for ParseError {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum AssembleError {
|
||||
ParseError(usize, ParseError),
|
||||
EquResolveError(usize, String, EvalError),
|
||||
EquDuplicateError(usize, String),
|
||||
OrgResolveError(usize, EvalError),
|
||||
ArgError(usize, EvalError),
|
||||
ParseError(Location, ParseError),
|
||||
EquResolveError(Location, String, EvalError),
|
||||
EquDuplicateError(Location, String),
|
||||
OrgResolveError(Location, EvalError),
|
||||
ArgError(Location, EvalError),
|
||||
NoCode,
|
||||
IncludeError(usize, String),
|
||||
IncludeError(Location, String),
|
||||
FileError(String),
|
||||
MacroError(usize),
|
||||
MacroError(Location),
|
||||
}
|
||||
|
||||
impl Display for AssembleError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AssembleError::EquResolveError(line, name, err) => {
|
||||
write!(f, "Cannot resolve .equ {} on line {}: {}", name, line, err)
|
||||
write!(f, "Cannot resolve .equ {} at {}: {}", name, line, err)
|
||||
}
|
||||
AssembleError::EquDuplicateError(line, name) => {
|
||||
write!(f, "Duplicate .equ {} on line {}", name, line)
|
||||
write!(f, "Duplicate .equ {} at {}", name, line)
|
||||
}
|
||||
AssembleError::OrgResolveError(line, err) => {
|
||||
write!(f, "Cannot resolve .org on line {}: {}", line, err)
|
||||
write!(f, "Cannot resolve .org at {}: {}", line, err)
|
||||
}
|
||||
AssembleError::ArgError(line, err) => {
|
||||
write!(f, "Cannot calculate argument on line {}: {}", line, err)
|
||||
write!(f, "Cannot calculate argument at {}: {}", line, err)
|
||||
}
|
||||
AssembleError::NoCode => {
|
||||
write!(f, "No output would be generated by this code")
|
||||
}
|
||||
AssembleError::ParseError(line, err) => {
|
||||
write!(f, "Parse error on line {}: {}", line, err)
|
||||
write!(f, "Parse error at {}: {}", line, err)
|
||||
}
|
||||
AssembleError::IncludeError(line, file) => {
|
||||
write!(f, "Cannot read \"{}\" on line {}", file, line)
|
||||
write!(f, "Cannot read \"{}\" at {}", file, line)
|
||||
}
|
||||
AssembleError::MacroError(line) => {
|
||||
write!(f, "Malformed macro control structure on line {}", line)
|
||||
write!(f, "Malformed macro control structure at {}", line)
|
||||
}
|
||||
AssembleError::FileError(file) => {
|
||||
write!(f, "File read error in {}", file)
|
||||
|
||||
Reference in New Issue
Block a user