1use pest::error::Error;
2
3use snafu::{Backtrace, IntoError, Snafu};
4
5use super::Rule;
6
7#[derive(Snafu, Debug)]
9#[snafu(context(suffix(false)), visibility(pub(super)))]
10#[non_exhaustive]
11pub enum ParseError {
12 #[snafu(display("an immediate value was too large for the given opcode"))]
14 #[non_exhaustive]
15 ImmediateTooLarge {
16 backtrace: Backtrace,
18 },
19
20 #[snafu(display("lexing failed"))]
22 #[non_exhaustive]
23 Lexer {
24 source: Box<dyn std::error::Error>,
26
27 backtrace: Backtrace,
29 },
30
31 #[snafu(display("expected {} argument(s) but only got {}", expected, got))]
33 #[non_exhaustive]
34 MissingArgument {
35 expected: usize,
37
38 got: usize,
40
41 backtrace: Backtrace,
43 },
44
45 #[snafu(display("extra argument (expected {})", expected))]
47 #[non_exhaustive]
48 ExtraArgument {
49 expected: usize,
51
52 backtrace: Backtrace,
54 },
55
56 #[snafu(display("incorrect argument type"))]
58 #[non_exhaustive]
59 ArgumentType {
60 backtrace: Backtrace,
62 },
63}
64
65impl From<Error<Rule>> for ParseError {
66 fn from(err: Error<Rule>) -> Self {
67 Lexer {}.into_error(Box::new(err))
68 }
69}