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
use super::*;
use crate::parsing::ForeignInterfaceError;

impl From<ForeignInterfaceError> for NyarError {
    fn from(value: ForeignInterfaceError) -> Self {
        Self { kind: Box::new(NyarErrorKind::Parsing(value.into())), level: value.into() }
    }
}

impl Into<SyntaxError> for ForeignInterfaceError {
    fn into(self) -> SyntaxError {
        match self {
            Self::MissingForeignMark { span } => SyntaxError::new("foreign mark not found".to_string()).with_span(span),
            Self::MissingForeignFlag { kind, hint, span } => {
                SyntaxError::new(format!("foreign {kind} must mark as `{hint}`")).with_span(span)
            }
            Self::InvalidForeignModule { span } => SyntaxError::new("foreign module not found".to_string()).with_span(span),
            Self::InvalidForeignName { span } => SyntaxError::new("foreign name not found".to_string()).with_span(span),
        }
    }
}

impl Into<ReportKind> for ForeignInterfaceError {
    fn into(self) -> ReportKind {
        match self {
            Self::MissingForeignMark { .. } => ReportKind::Trace,
            Self::MissingForeignFlag { .. } => ReportKind::Alert,
            Self::InvalidForeignModule { .. } => ReportKind::Error,
            Self::InvalidForeignName { .. } => ReportKind::Error,
        }
    }
}