rasn_compiler/intermediate/
error.rs

1use std::{
2    error::Error,
3    fmt::{Display, Formatter, Result},
4};
5
6#[derive(Debug, Clone, PartialEq)]
7pub struct GrammarError {
8    pub details: String,
9    pub kind: GrammarErrorType,
10    pub pdu: Option<String>,
11}
12
13impl GrammarError {
14    pub fn new(data_details: &str, kind: GrammarErrorType) -> Self {
15        GrammarError {
16            details: data_details.into(),
17            kind,
18            pdu: None,
19        }
20    }
21
22    pub fn todo() -> Self {
23        GrammarError {
24            details: "Not yet implemented!".into(),
25            kind: GrammarErrorType::NotYetInplemented,
26            pdu: None,
27        }
28    }
29
30    pub fn contextualize(&mut self, pdu: &str) {
31        self.pdu = Some(pdu.into());
32    }
33}
34
35impl Error for GrammarError {}
36
37#[derive(Debug, Clone, PartialEq)]
38pub enum GrammarErrorType {
39    UnpackingError,
40    LinkerError,
41    PerVisibleConstraintError,
42    NotYetInplemented,
43    SyntaxMismatch,
44}
45
46impl Display for GrammarError {
47    fn fmt(&self, f: &mut Formatter) -> Result {
48        write!(f, "{:?} in ASN grammar: {}", self.kind, self.details)
49    }
50}