Files
vulcan/vasm/src/parse_error.rs
T

26 lines
659 B
Rust
Raw Normal View History

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
#[derive(Debug, PartialEq)]
2022-03-13 15:44:48 -05:00
pub enum ParseError<'a> {
LineParseFailure,
2022-03-14 01:04:08 -05:00
InvalidInstruction(&'a str),
2022-03-13 15:44:48 -05:00
}
2022-03-12 15:39:29 -06:00
2022-03-13 15:44:48 -05:00
impl<'a> From<InvalidMnemonic<'a>> for ParseError<'a> {
fn from(err: InvalidMnemonic<'a>) -> Self {
Self::InvalidInstruction(err.0)
2022-03-12 15:39:29 -06:00
}
}
2022-03-13 15:44:48 -05:00
impl<'a> Display for ParseError<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
use ParseError::*;
match self {
LineParseFailure => write!(f, "Failed to parse line"),
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
}