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