1use std::num::TryFromIntError;
4
5use thiserror::Error as ThisError;
6
7use corewars_core::load_file::Opcode;
8
9#[derive(ThisError, Debug, PartialEq)]
13pub enum Error {
14 #[error("no such label {label:?}")]
16 LabelNotFound { label: String, line: Option<usize> },
17
18 #[error("invalid origin specified")]
20 InvalidOrigin(#[from] TryFromIntError),
21
22 #[error("invalid syntax")]
24 InvalidSyntax(#[from] super::grammar::SyntaxError),
25
26 #[error("expected additional arguments for {opcode} opcode")]
28 InvalidArguments { opcode: Opcode },
29}
30
31#[derive(ThisError, Debug, PartialEq)]
33pub enum Warning {
34 #[error("origin already defined as {old:?}, new definition {new:?} will be ignored")]
36 OriginRedefinition { old: String, new: String },
37
38 #[error("right-hand side of substitution for label {0:?} is empty")]
40 EmptySubstitution(String),
41
42 #[error("no instruction offset for label {0:?}, it will not b")]
44 EmptyOffset(String),
45}