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