logicaffeine_kernel/interface/
error.rs1use crate::KernelError;
4use std::fmt;
5
6#[derive(Debug)]
8pub enum InterfaceError {
9 Parse(ParseError),
11
12 Kernel(KernelError),
14}
15
16#[derive(Debug, Clone)]
18pub enum ParseError {
19 UnexpectedEof,
21
22 UnknownCommand(String),
24
25 Expected { expected: String, found: String },
27
28 InvalidIdent(String),
30
31 InvalidNumber(String),
33
34 Missing(String),
36
37 MissingEitherClause,
43
44 MissingVariantName,
46
47 InvalidConsiderSyntax(String),
49
50 MissingYield,
52
53 MissingWhenClause,
55
56 UnclosedConsiderBlock,
58}
59
60impl fmt::Display for InterfaceError {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match self {
63 InterfaceError::Parse(e) => write!(f, "Parse error: {}", e),
64 InterfaceError::Kernel(e) => write!(f, "Kernel error: {}", e),
65 }
66 }
67}
68
69impl fmt::Display for ParseError {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 match self {
72 ParseError::UnexpectedEof => write!(f, "Unexpected end of input"),
73 ParseError::UnknownCommand(cmd) => write!(f, "Unknown command: {}", cmd),
74 ParseError::Expected { expected, found } => {
75 write!(f, "Expected {}, found {}", expected, found)
76 }
77 ParseError::InvalidIdent(s) => write!(f, "Invalid identifier: {}", s),
78 ParseError::InvalidNumber(s) => write!(f, "Invalid number literal: {}", s),
79 ParseError::Missing(what) => write!(f, "Missing {}", what),
80 ParseError::MissingEitherClause => write!(f, "Missing 'is either' clause in type definition"),
82 ParseError::MissingVariantName => write!(f, "Missing variant name in type definition"),
83 ParseError::InvalidConsiderSyntax(msg) => write!(f, "Invalid Consider syntax: {}", msg),
84 ParseError::MissingYield => write!(f, "Missing 'Yield' in function body"),
85 ParseError::MissingWhenClause => write!(f, "Missing 'When' clause in Consider block"),
86 ParseError::UnclosedConsiderBlock => write!(f, "Unclosed Consider block"),
87 }
88 }
89}
90
91impl std::error::Error for InterfaceError {}
92impl std::error::Error for ParseError {}
93
94impl From<ParseError> for InterfaceError {
95 fn from(e: ParseError) -> Self {
96 InterfaceError::Parse(e)
97 }
98}
99
100impl From<KernelError> for InterfaceError {
101 fn from(e: KernelError) -> Self {
102 InterfaceError::Kernel(e)
103 }
104}