layer_tl_parser/
errors.rs1use std::fmt;
2use std::num::ParseIntError;
3
4#[derive(Clone, Debug, PartialEq)]
6pub enum ParamParseError {
7 Empty,
9 TypeDef {
11 name: String,
13 },
14 MissingDef,
16 InvalidFlag,
18 InvalidGeneric,
20 NotImplemented,
22}
23
24impl fmt::Display for ParamParseError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Self::Empty => write!(f, "empty token"),
28 Self::TypeDef { name } => write!(f, "generic type definition: {name}"),
29 Self::MissingDef => write!(f, "unknown generic or flag definition"),
30 Self::InvalidFlag => write!(f, "invalid flag expression"),
31 Self::InvalidGeneric => write!(f, "invalid generic argument (unclosed `<`)"),
32 Self::NotImplemented => write!(f, "parameter without `:type` is not supported"),
33 }
34 }
35}
36
37impl std::error::Error for ParamParseError {}
38
39#[derive(Debug, PartialEq)]
41pub enum ParseError {
42 Empty,
44 MissingType,
46 MissingName,
48 InvalidId(ParseIntError),
50 InvalidParam(ParamParseError),
52 NotImplemented,
54}
55
56impl fmt::Display for ParseError {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 match self {
59 Self::Empty => write!(f, "empty definition"),
60 Self::MissingType => write!(f, "missing `= Type`"),
61 Self::MissingName => write!(f, "missing or malformed name"),
62 Self::InvalidId(e) => write!(f, "invalid constructor ID: {e}"),
63 Self::InvalidParam(e) => write!(f, "invalid parameter: {e}"),
64 Self::NotImplemented => write!(f, "unsupported TL syntax"),
65 }
66 }
67}
68
69impl std::error::Error for ParseError {
70 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
71 match self {
72 Self::InvalidId(e) => Some(e),
73 Self::InvalidParam(e) => Some(e),
74 _ => None,
75 }
76 }
77}