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