aldrin_parser/
error.rs

1mod const_int_not_found;
2mod duplicate_definition;
3mod duplicate_enum_variant;
4mod duplicate_enum_variant_id;
5mod duplicate_event_id;
6mod duplicate_function_id;
7mod duplicate_service_item;
8mod duplicate_service_uuid;
9mod duplicate_struct_field;
10mod duplicate_struct_field_id;
11mod empty_enum;
12mod expected_const_int_found_service;
13mod expected_const_int_found_string;
14mod expected_const_int_found_type;
15mod expected_const_int_found_uuid;
16mod expected_ident_found_reserved;
17mod expected_type_found_const;
18mod expected_type_found_service;
19mod import_not_found;
20mod invalid_array_len;
21mod invalid_const_value;
22mod invalid_enum_variant_id;
23mod invalid_event_id;
24mod invalid_function_id;
25mod invalid_schema_name;
26mod invalid_service_uuid;
27mod invalid_service_version;
28mod invalid_struct_field_id;
29mod invalid_syntax;
30mod io_error;
31mod missing_import;
32mod recursive_type;
33mod type_not_found;
34
35use crate::diag::{Diagnostic, DiagnosticKind, Formatted};
36use crate::Parsed;
37
38pub use const_int_not_found::ConstIntNotFound;
39pub use duplicate_definition::DuplicateDefinition;
40pub use duplicate_enum_variant::DuplicateEnumVariant;
41pub use duplicate_enum_variant_id::DuplicateEnumVariantId;
42pub use duplicate_event_id::DuplicateEventId;
43pub use duplicate_function_id::DuplicateFunctionId;
44pub use duplicate_service_item::DuplicateServiceItem;
45pub use duplicate_service_uuid::DuplicateServiceUuid;
46pub use duplicate_struct_field::DuplicateStructField;
47pub use duplicate_struct_field_id::DuplicateStructFieldId;
48pub use empty_enum::EmptyEnum;
49pub use expected_const_int_found_service::ExpectedConstIntFoundService;
50pub use expected_const_int_found_string::ExpectedConstIntFoundString;
51pub use expected_const_int_found_type::ExpectedConstIntFoundType;
52pub use expected_const_int_found_uuid::ExpectedConstIntFoundUuid;
53pub use expected_ident_found_reserved::ExpectedIdentFoundReserved;
54pub use expected_type_found_const::ExpectedTypeFoundConst;
55pub use expected_type_found_service::ExpectedTypeFoundService;
56pub use import_not_found::ImportNotFound;
57pub use invalid_array_len::InvalidArrayLen;
58pub use invalid_const_value::InvalidConstValue;
59pub use invalid_enum_variant_id::InvalidEnumVariantId;
60pub use invalid_event_id::InvalidEventId;
61pub use invalid_function_id::InvalidFunctionId;
62pub use invalid_schema_name::InvalidSchemaName;
63pub use invalid_service_uuid::InvalidServiceUuid;
64pub use invalid_service_version::InvalidServiceVersion;
65pub use invalid_struct_field_id::InvalidStructFieldId;
66pub use invalid_syntax::{Expected, InvalidSyntax};
67pub use io_error::IoError;
68pub use missing_import::MissingImport;
69pub use recursive_type::{RecursiveEnum, RecursiveStruct};
70pub use type_not_found::TypeNotFound;
71
72#[derive(Debug)]
73#[non_exhaustive]
74pub enum Error {
75    ConstIntNotFound(ConstIntNotFound),
76    DuplicateDefinition(DuplicateDefinition),
77    DuplicateEnumVariant(DuplicateEnumVariant),
78    DuplicateEnumVariantId(DuplicateEnumVariantId),
79    DuplicateEventId(DuplicateEventId),
80    DuplicateFunctionId(DuplicateFunctionId),
81    DuplicateServiceItem(DuplicateServiceItem),
82    DuplicateServiceUuid(DuplicateServiceUuid),
83    DuplicateStructField(DuplicateStructField),
84    DuplicateStructFieldId(DuplicateStructFieldId),
85    EmptyEnum(EmptyEnum),
86    ExpectedConstIntFoundService(ExpectedConstIntFoundService),
87    ExpectedConstIntFoundString(ExpectedConstIntFoundString),
88    ExpectedConstIntFoundType(ExpectedConstIntFoundType),
89    ExpectedConstIntFoundUuid(ExpectedConstIntFoundUuid),
90    ExpectedIdentFoundReserved(ExpectedIdentFoundReserved),
91    ExpectedTypeFoundConst(ExpectedTypeFoundConst),
92    ExpectedTypeFoundService(ExpectedTypeFoundService),
93    ImportNotFound(ImportNotFound),
94    InvalidArrayLen(InvalidArrayLen),
95    InvalidConstValue(InvalidConstValue),
96    InvalidEnumVariantId(InvalidEnumVariantId),
97    InvalidEventId(InvalidEventId),
98    InvalidFunctionId(InvalidFunctionId),
99    InvalidSchemaName(InvalidSchemaName),
100    InvalidServiceUuid(InvalidServiceUuid),
101    InvalidServiceVersion(InvalidServiceVersion),
102    InvalidStructFieldId(InvalidStructFieldId),
103    InvalidSyntax(InvalidSyntax),
104    IoError(IoError),
105    MissingImport(MissingImport),
106    RecursiveEnum(RecursiveEnum),
107    RecursiveStruct(RecursiveStruct),
108    TypeNotFound(TypeNotFound),
109}
110
111impl Diagnostic for Error {
112    fn kind(&self) -> DiagnosticKind {
113        DiagnosticKind::Error
114    }
115
116    fn schema_name(&self) -> &str {
117        match self {
118            Self::ConstIntNotFound(e) => e.schema_name(),
119            Self::DuplicateDefinition(e) => e.schema_name(),
120            Self::DuplicateEnumVariant(e) => e.schema_name(),
121            Self::DuplicateEnumVariantId(e) => e.schema_name(),
122            Self::DuplicateEventId(e) => e.schema_name(),
123            Self::DuplicateFunctionId(e) => e.schema_name(),
124            Self::DuplicateServiceItem(e) => e.schema_name(),
125            Self::DuplicateServiceUuid(e) => e.schema_name(),
126            Self::DuplicateStructField(e) => e.schema_name(),
127            Self::DuplicateStructFieldId(e) => e.schema_name(),
128            Self::EmptyEnum(e) => e.schema_name(),
129            Self::ExpectedConstIntFoundService(e) => e.schema_name(),
130            Self::ExpectedConstIntFoundString(e) => e.schema_name(),
131            Self::ExpectedConstIntFoundType(e) => e.schema_name(),
132            Self::ExpectedConstIntFoundUuid(e) => e.schema_name(),
133            Self::ExpectedIdentFoundReserved(e) => e.schema_name(),
134            Self::ExpectedTypeFoundConst(e) => e.schema_name(),
135            Self::ExpectedTypeFoundService(e) => e.schema_name(),
136            Self::ImportNotFound(e) => e.schema_name(),
137            Self::InvalidArrayLen(e) => e.schema_name(),
138            Self::InvalidConstValue(e) => e.schema_name(),
139            Self::InvalidEnumVariantId(e) => e.schema_name(),
140            Self::InvalidEventId(e) => e.schema_name(),
141            Self::InvalidFunctionId(e) => e.schema_name(),
142            Self::InvalidSchemaName(e) => e.schema_name(),
143            Self::InvalidServiceUuid(e) => e.schema_name(),
144            Self::InvalidServiceVersion(e) => e.schema_name(),
145            Self::InvalidStructFieldId(e) => e.schema_name(),
146            Self::InvalidSyntax(e) => e.schema_name(),
147            Self::IoError(e) => e.schema_name(),
148            Self::MissingImport(e) => e.schema_name(),
149            Self::RecursiveEnum(e) => e.schema_name(),
150            Self::RecursiveStruct(e) => e.schema_name(),
151            Self::TypeNotFound(e) => e.schema_name(),
152        }
153    }
154
155    fn format<'a>(&'a self, parsed: &'a Parsed) -> Formatted<'a> {
156        match self {
157            Self::ConstIntNotFound(e) => e.format(parsed),
158            Self::DuplicateDefinition(e) => e.format(parsed),
159            Self::DuplicateEnumVariant(e) => e.format(parsed),
160            Self::DuplicateEnumVariantId(e) => e.format(parsed),
161            Self::DuplicateEventId(e) => e.format(parsed),
162            Self::DuplicateFunctionId(e) => e.format(parsed),
163            Self::DuplicateServiceItem(e) => e.format(parsed),
164            Self::DuplicateServiceUuid(e) => e.format(parsed),
165            Self::DuplicateStructField(e) => e.format(parsed),
166            Self::DuplicateStructFieldId(e) => e.format(parsed),
167            Self::EmptyEnum(e) => e.format(parsed),
168            Self::ExpectedConstIntFoundService(e) => e.format(parsed),
169            Self::ExpectedConstIntFoundString(e) => e.format(parsed),
170            Self::ExpectedConstIntFoundType(e) => e.format(parsed),
171            Self::ExpectedConstIntFoundUuid(e) => e.format(parsed),
172            Self::ExpectedIdentFoundReserved(e) => e.format(parsed),
173            Self::ExpectedTypeFoundConst(e) => e.format(parsed),
174            Self::ExpectedTypeFoundService(e) => e.format(parsed),
175            Self::ImportNotFound(e) => e.format(parsed),
176            Self::InvalidArrayLen(e) => e.format(parsed),
177            Self::InvalidConstValue(e) => e.format(parsed),
178            Self::InvalidEnumVariantId(e) => e.format(parsed),
179            Self::InvalidEventId(e) => e.format(parsed),
180            Self::InvalidFunctionId(e) => e.format(parsed),
181            Self::InvalidSchemaName(e) => e.format(parsed),
182            Self::InvalidServiceUuid(e) => e.format(parsed),
183            Self::InvalidServiceVersion(e) => e.format(parsed),
184            Self::InvalidStructFieldId(e) => e.format(parsed),
185            Self::InvalidSyntax(e) => e.format(parsed),
186            Self::IoError(e) => e.format(parsed),
187            Self::MissingImport(e) => e.format(parsed),
188            Self::RecursiveEnum(e) => e.format(parsed),
189            Self::RecursiveStruct(e) => e.format(parsed),
190            Self::TypeNotFound(e) => e.format(parsed),
191        }
192    }
193}