rasn_compiler/intermediate/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::{
    error::Error,
    fmt::{Display, Formatter, Result},
};

#[derive(Debug, Clone, PartialEq)]
pub struct GrammarError {
    pub details: String,
    pub kind: GrammarErrorType,
    pub pdu: Option<String>,
}

impl GrammarError {
    pub fn new(data_details: &str, kind: GrammarErrorType) -> Self {
        GrammarError {
            details: data_details.into(),
            kind,
            pdu: None,
        }
    }

    pub fn todo() -> Self {
        GrammarError {
            details: "Not yet implemented!".into(),
            kind: GrammarErrorType::NotYetInplemented,
            pdu: None,
        }
    }

    pub fn contextualize(&mut self, pdu: &str) {
        self.pdu = Some(pdu.into());
    }
}

impl Error for GrammarError {}

#[derive(Debug, Clone, PartialEq)]
pub enum GrammarErrorType {
    UnpackingError,
    LinkerError,
    PerVisibleConstraintError,
    NotYetInplemented,
    SyntaxMismatch,
}

impl Display for GrammarError {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "{:?} in ASN grammar: {}", self.kind, self.details)
    }
}