aldrin_parser/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
mod const_int_not_found;
mod duplicate_definition;
mod duplicate_enum_variant;
mod duplicate_enum_variant_id;
mod duplicate_event_id;
mod duplicate_function_id;
mod duplicate_service_item;
mod duplicate_service_uuid;
mod duplicate_struct_field;
mod duplicate_struct_field_id;
mod empty_enum;
mod expected_const_int_found_service;
mod expected_const_int_found_string;
mod expected_const_int_found_type;
mod expected_const_int_found_uuid;
mod expected_type_found_const;
mod expected_type_found_service;
mod import_not_found;
mod invalid_array_len;
mod invalid_const_value;
mod invalid_enum_variant_id;
mod invalid_event_id;
mod invalid_function_id;
mod invalid_schema_name;
mod invalid_service_uuid;
mod invalid_service_version;
mod invalid_struct_field_id;
mod invalid_syntax;
mod io_error;
mod keyword_as_ident;
mod missing_import;
mod recursive_type;
mod type_not_found;

use crate::diag::{Diagnostic, DiagnosticKind, Formatted};
use crate::Parsed;

pub use const_int_not_found::ConstIntNotFound;
pub use duplicate_definition::DuplicateDefinition;
pub use duplicate_enum_variant::DuplicateEnumVariant;
pub use duplicate_enum_variant_id::DuplicateEnumVariantId;
pub use duplicate_event_id::DuplicateEventId;
pub use duplicate_function_id::DuplicateFunctionId;
pub use duplicate_service_item::DuplicateServiceItem;
pub use duplicate_service_uuid::DuplicateServiceUuid;
pub use duplicate_struct_field::DuplicateStructField;
pub use duplicate_struct_field_id::DuplicateStructFieldId;
pub use empty_enum::EmptyEnum;
pub use expected_const_int_found_service::ExpectedConstIntFoundService;
pub use expected_const_int_found_string::ExpectedConstIntFoundString;
pub use expected_const_int_found_type::ExpectedConstIntFoundType;
pub use expected_const_int_found_uuid::ExpectedConstIntFoundUuid;
pub use expected_type_found_const::ExpectedTypeFoundConst;
pub use expected_type_found_service::ExpectedTypeFoundService;
pub use import_not_found::ImportNotFound;
pub use invalid_array_len::InvalidArrayLen;
pub use invalid_const_value::InvalidConstValue;
pub use invalid_enum_variant_id::InvalidEnumVariantId;
pub use invalid_event_id::InvalidEventId;
pub use invalid_function_id::InvalidFunctionId;
pub use invalid_schema_name::InvalidSchemaName;
pub use invalid_service_uuid::InvalidServiceUuid;
pub use invalid_service_version::InvalidServiceVersion;
pub use invalid_struct_field_id::InvalidStructFieldId;
pub use invalid_syntax::{Expected, InvalidSyntax};
pub use io_error::IoError;
pub use keyword_as_ident::KeywordAsIdent;
pub use missing_import::MissingImport;
pub use recursive_type::{RecursiveEnum, RecursiveStruct};
pub use type_not_found::TypeNotFound;

#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
    ConstIntNotFound(ConstIntNotFound),
    DuplicateDefinition(DuplicateDefinition),
    DuplicateEnumVariant(DuplicateEnumVariant),
    DuplicateEnumVariantId(DuplicateEnumVariantId),
    DuplicateEventId(DuplicateEventId),
    DuplicateFunctionId(DuplicateFunctionId),
    DuplicateServiceItem(DuplicateServiceItem),
    DuplicateServiceUuid(DuplicateServiceUuid),
    DuplicateStructField(DuplicateStructField),
    DuplicateStructFieldId(DuplicateStructFieldId),
    EmptyEnum(EmptyEnum),
    ExpectedConstIntFoundService(ExpectedConstIntFoundService),
    ExpectedConstIntFoundString(ExpectedConstIntFoundString),
    ExpectedConstIntFoundType(ExpectedConstIntFoundType),
    ExpectedConstIntFoundUuid(ExpectedConstIntFoundUuid),
    ExpectedTypeFoundConst(ExpectedTypeFoundConst),
    ExpectedTypeFoundService(ExpectedTypeFoundService),
    ImportNotFound(ImportNotFound),
    InvalidArrayLen(InvalidArrayLen),
    InvalidConstValue(InvalidConstValue),
    InvalidEnumVariantId(InvalidEnumVariantId),
    InvalidEventId(InvalidEventId),
    InvalidFunctionId(InvalidFunctionId),
    InvalidSchemaName(InvalidSchemaName),
    InvalidServiceUuid(InvalidServiceUuid),
    InvalidServiceVersion(InvalidServiceVersion),
    InvalidStructFieldId(InvalidStructFieldId),
    InvalidSyntax(InvalidSyntax),
    IoError(IoError),
    KeywordAsIdent(KeywordAsIdent),
    MissingImport(MissingImport),
    RecursiveEnum(RecursiveEnum),
    RecursiveStruct(RecursiveStruct),
    TypeNotFound(TypeNotFound),
}

impl Diagnostic for Error {
    fn kind(&self) -> DiagnosticKind {
        DiagnosticKind::Error
    }

    fn schema_name(&self) -> &str {
        match self {
            Self::ConstIntNotFound(e) => e.schema_name(),
            Self::DuplicateDefinition(e) => e.schema_name(),
            Self::DuplicateEnumVariant(e) => e.schema_name(),
            Self::DuplicateEnumVariantId(e) => e.schema_name(),
            Self::DuplicateEventId(e) => e.schema_name(),
            Self::DuplicateFunctionId(e) => e.schema_name(),
            Self::DuplicateServiceItem(e) => e.schema_name(),
            Self::DuplicateServiceUuid(e) => e.schema_name(),
            Self::DuplicateStructField(e) => e.schema_name(),
            Self::DuplicateStructFieldId(e) => e.schema_name(),
            Self::EmptyEnum(e) => e.schema_name(),
            Self::ExpectedConstIntFoundService(e) => e.schema_name(),
            Self::ExpectedConstIntFoundString(e) => e.schema_name(),
            Self::ExpectedConstIntFoundType(e) => e.schema_name(),
            Self::ExpectedConstIntFoundUuid(e) => e.schema_name(),
            Self::ExpectedTypeFoundConst(e) => e.schema_name(),
            Self::ExpectedTypeFoundService(e) => e.schema_name(),
            Self::ImportNotFound(e) => e.schema_name(),
            Self::InvalidArrayLen(e) => e.schema_name(),
            Self::InvalidConstValue(e) => e.schema_name(),
            Self::InvalidEnumVariantId(e) => e.schema_name(),
            Self::InvalidEventId(e) => e.schema_name(),
            Self::InvalidFunctionId(e) => e.schema_name(),
            Self::InvalidSchemaName(e) => e.schema_name(),
            Self::InvalidServiceUuid(e) => e.schema_name(),
            Self::InvalidServiceVersion(e) => e.schema_name(),
            Self::InvalidStructFieldId(e) => e.schema_name(),
            Self::InvalidSyntax(e) => e.schema_name(),
            Self::IoError(e) => e.schema_name(),
            Self::KeywordAsIdent(e) => e.schema_name(),
            Self::MissingImport(e) => e.schema_name(),
            Self::RecursiveEnum(e) => e.schema_name(),
            Self::RecursiveStruct(e) => e.schema_name(),
            Self::TypeNotFound(e) => e.schema_name(),
        }
    }

    fn format<'a>(&'a self, parsed: &'a Parsed) -> Formatted<'a> {
        match self {
            Self::ConstIntNotFound(e) => e.format(parsed),
            Self::DuplicateDefinition(e) => e.format(parsed),
            Self::DuplicateEnumVariant(e) => e.format(parsed),
            Self::DuplicateEnumVariantId(e) => e.format(parsed),
            Self::DuplicateEventId(e) => e.format(parsed),
            Self::DuplicateFunctionId(e) => e.format(parsed),
            Self::DuplicateServiceItem(e) => e.format(parsed),
            Self::DuplicateServiceUuid(e) => e.format(parsed),
            Self::DuplicateStructField(e) => e.format(parsed),
            Self::DuplicateStructFieldId(e) => e.format(parsed),
            Self::EmptyEnum(e) => e.format(parsed),
            Self::ExpectedConstIntFoundService(e) => e.format(parsed),
            Self::ExpectedConstIntFoundString(e) => e.format(parsed),
            Self::ExpectedConstIntFoundType(e) => e.format(parsed),
            Self::ExpectedConstIntFoundUuid(e) => e.format(parsed),
            Self::ExpectedTypeFoundConst(e) => e.format(parsed),
            Self::ExpectedTypeFoundService(e) => e.format(parsed),
            Self::ImportNotFound(e) => e.format(parsed),
            Self::InvalidArrayLen(e) => e.format(parsed),
            Self::InvalidConstValue(e) => e.format(parsed),
            Self::InvalidEnumVariantId(e) => e.format(parsed),
            Self::InvalidEventId(e) => e.format(parsed),
            Self::InvalidFunctionId(e) => e.format(parsed),
            Self::InvalidSchemaName(e) => e.format(parsed),
            Self::InvalidServiceUuid(e) => e.format(parsed),
            Self::InvalidServiceVersion(e) => e.format(parsed),
            Self::InvalidStructFieldId(e) => e.format(parsed),
            Self::InvalidSyntax(e) => e.format(parsed),
            Self::IoError(e) => e.format(parsed),
            Self::KeywordAsIdent(e) => e.format(parsed),
            Self::MissingImport(e) => e.format(parsed),
            Self::RecursiveEnum(e) => e.format(parsed),
            Self::RecursiveStruct(e) => e.format(parsed),
            Self::TypeNotFound(e) => e.format(parsed),
        }
    }
}