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