More parser implementation
This commit is contained in:
+21
-5
@@ -1,10 +1,26 @@
|
||||
use vcore::opcodes::InvalidOpcode;
|
||||
use vcore::opcodes::{InvalidMnemonic};
|
||||
use pest::iterators::Pair;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use crate::vasm_parser::Rule;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ParseError<'a>(pub &'a str);
|
||||
pub enum ParseError<'a> {
|
||||
LineParseFailure,
|
||||
InvalidInstruction(&'a str)
|
||||
}
|
||||
|
||||
impl<'a> From<InvalidOpcode> for ParseError<'a> {
|
||||
fn from(_: InvalidOpcode) -> Self {
|
||||
Self("Invalid opcode")
|
||||
impl<'a> From<InvalidMnemonic<'a>> for ParseError<'a> {
|
||||
fn from(err: InvalidMnemonic<'a>) -> Self {
|
||||
Self::InvalidInstruction(err.0)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user