ferogram_tl_parser/
errors.rs1use std::fmt;
12use std::num::ParseIntError;
13
14#[derive(Clone, Debug, PartialEq)]
16pub enum ParamParseError {
17 Empty,
19 TypeDef {
21 name: String,
23 },
24 MissingDef,
26 InvalidFlag,
28 InvalidGeneric,
30 NotImplemented,
32}
33
34impl fmt::Display for ParamParseError {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 match self {
37 Self::Empty => write!(f, "empty token"),
38 Self::TypeDef { name } => write!(f, "generic type definition: {name}"),
39 Self::MissingDef => write!(f, "unknown generic or flag definition"),
40 Self::InvalidFlag => write!(f, "invalid flag expression"),
41 Self::InvalidGeneric => write!(f, "invalid generic argument (unclosed `<`)"),
42 Self::NotImplemented => write!(f, "parameter without `:type` is not supported"),
43 }
44 }
45}
46
47impl std::error::Error for ParamParseError {}
48
49#[derive(Debug, PartialEq)]
51pub enum ParseError {
52 Empty,
54 MissingType,
56 MissingName,
58 InvalidId(ParseIntError),
60 InvalidParam(ParamParseError),
62 NotImplemented,
64}
65
66impl fmt::Display for ParseError {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 match self {
69 Self::Empty => write!(f, "empty definition"),
70 Self::MissingType => write!(f, "missing `= Type`"),
71 Self::MissingName => write!(f, "missing or malformed name"),
72 Self::InvalidId(e) => write!(f, "invalid constructor ID: {e}"),
73 Self::InvalidParam(e) => write!(f, "invalid parameter: {e}"),
74 Self::NotImplemented => write!(f, "unsupported TL syntax"),
75 }
76 }
77}
78
79impl std::error::Error for ParseError {
80 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
81 match self {
82 Self::InvalidId(e) => Some(e),
83 Self::InvalidParam(e) => Some(e),
84 _ => None,
85 }
86 }
87}