2022-03-13 15:44:48 -05:00
|
|
|
use std::fmt::{Display, Formatter};
|
2022-03-14 01:04:08 -05:00
|
|
|
|
|
|
|
|
use vcore::opcodes::InvalidMnemonic;
|
2022-03-12 15:39:29 -06:00
|
|
|
|
2022-04-02 00:15:33 -05:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2022-04-05 18:05:24 -05:00
|
|
|
pub enum ParseError {
|
2022-03-13 15:44:48 -05:00
|
|
|
LineParseFailure,
|
2022-04-05 18:05:24 -05:00
|
|
|
InvalidInstruction(String),
|
2022-03-13 15:44:48 -05:00
|
|
|
}
|
2022-03-12 15:39:29 -06:00
|
|
|
|
2022-04-05 18:05:24 -05:00
|
|
|
impl<'a> From<InvalidMnemonic<'a>> for ParseError {
|
2022-03-13 15:44:48 -05:00
|
|
|
fn from(err: InvalidMnemonic<'a>) -> Self {
|
2022-04-05 18:05:24 -05:00
|
|
|
Self::InvalidInstruction(err.0.into())
|
2022-03-12 15:39:29 -06:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-13 15:44:48 -05:00
|
|
|
|
2022-04-05 18:05:24 -05:00
|
|
|
impl Display for ParseError {
|
2022-03-13 15:44:48 -05:00
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
use ParseError::*;
|
|
|
|
|
match self {
|
|
|
|
|
LineParseFailure => write!(f, "Failed to parse line"),
|
2022-03-15 22:50:19 -05:00
|
|
|
InvalidInstruction(p) => write!(f, "Cannot parse {} as instruction", p),
|
2022-03-13 15:44:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-14 01:04:08 -05:00
|
|
|
}
|