1use serde::Serialize;
2
3use mago_span::HasSpan;
4use mago_span::Span;
5
6pub use crate::ast::alias_reference::*;
7pub use crate::ast::array::*;
8pub use crate::ast::callable::*;
9pub use crate::ast::class_like_string::*;
10pub use crate::ast::composite::*;
11pub use crate::ast::conditional::*;
12pub use crate::ast::generics::*;
13pub use crate::ast::identifier::*;
14pub use crate::ast::index_access::*;
15pub use crate::ast::int_mask::*;
16pub use crate::ast::int_range::*;
17pub use crate::ast::iterable::*;
18pub use crate::ast::key_of::*;
19pub use crate::ast::keyword::*;
20pub use crate::ast::literal::*;
21pub use crate::ast::new::*;
22use crate::ast::object::ObjectType;
23pub use crate::ast::properties_of::*;
24pub use crate::ast::reference::*;
25pub use crate::ast::shape::*;
26pub use crate::ast::slice::*;
27pub use crate::ast::template_type::*;
28pub use crate::ast::unary::*;
29pub use crate::ast::value_of::*;
30pub use crate::ast::variable::*;
31pub use crate::ast::wildcard::*;
32
33pub mod alias_reference;
34pub mod array;
35pub mod callable;
36pub mod class_like_string;
37pub mod composite;
38pub mod conditional;
39pub mod generics;
40pub mod identifier;
41pub mod index_access;
42pub mod int_mask;
43pub mod int_range;
44pub mod iterable;
45pub mod key_of;
46pub mod keyword;
47pub mod literal;
48pub mod new;
49pub mod object;
50pub mod properties_of;
51pub mod reference;
52pub mod shape;
53pub mod slice;
54pub mod template_type;
55pub mod unary;
56pub mod value_of;
57pub mod variable;
58pub mod wildcard;
59
60#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, PartialOrd, Ord)]
61#[serde(tag = "type", content = "value")]
62#[non_exhaustive]
63pub enum Type<'input> {
64 Parenthesized(ParenthesizedType<'input>),
65 Union(UnionType<'input>),
66 Intersection(IntersectionType<'input>),
67 Nullable(NullableType<'input>),
68 Array(ArrayType<'input>),
69 NonEmptyArray(NonEmptyArrayType<'input>),
70 AssociativeArray(AssociativeArrayType<'input>),
71 List(ListType<'input>),
72 NonEmptyList(NonEmptyListType<'input>),
73 Iterable(IterableType<'input>),
74 ClassString(ClassStringType<'input>),
75 InterfaceString(InterfaceStringType<'input>),
76 EnumString(EnumStringType<'input>),
77 TraitString(TraitStringType<'input>),
78 Reference(ReferenceType<'input>),
79 Mixed(Keyword<'input>),
80 NonEmptyMixed(Keyword<'input>),
81 Null(Keyword<'input>),
82 Void(Keyword<'input>),
83 Never(Keyword<'input>),
84 Resource(Keyword<'input>),
85 ClosedResource(Keyword<'input>),
86 OpenResource(Keyword<'input>),
87 True(Keyword<'input>),
88 False(Keyword<'input>),
89 Bool(Keyword<'input>),
90 Float(Keyword<'input>),
91 Int(Keyword<'input>),
92 PositiveInt(Keyword<'input>),
93 NegativeInt(Keyword<'input>),
94 NonPositiveInt(Keyword<'input>),
95 NonNegativeInt(Keyword<'input>),
96 String(Keyword<'input>),
97 StringableObject(Keyword<'input>),
98 ArrayKey(Keyword<'input>),
99 Object(ObjectType<'input>),
100 Numeric(Keyword<'input>),
101 Scalar(Keyword<'input>),
102 CallableString(Keyword<'input>),
103 LowercaseCallableString(Keyword<'input>),
104 UppercaseCallableString(Keyword<'input>),
105 NumericString(Keyword<'input>),
106 NonEmptyString(Keyword<'input>),
107 NonEmptyLowercaseString(Keyword<'input>),
108 LowercaseString(Keyword<'input>),
109 NonEmptyUppercaseString(Keyword<'input>),
110 UppercaseString(Keyword<'input>),
111 TruthyString(Keyword<'input>),
112 NonFalsyString(Keyword<'input>),
113 UnspecifiedLiteralInt(Keyword<'input>),
114 UnspecifiedLiteralString(Keyword<'input>),
115 UnspecifiedLiteralFloat(Keyword<'input>),
116 NonEmptyUnspecifiedLiteralString(Keyword<'input>),
117 LiteralFloat(LiteralFloatType<'input>),
118 LiteralInt(LiteralIntType<'input>),
119 LiteralString(LiteralStringType<'input>),
120 MemberReference(MemberReferenceType<'input>),
121 AliasReference(AliasReferenceType<'input>),
122 Shape(ShapeType<'input>),
123 Callable(CallableType<'input>),
124 Variable(VariableType<'input>),
125 Conditional(ConditionalType<'input>),
126 KeyOf(KeyOfType<'input>),
127 ValueOf(ValueOfType<'input>),
128 IntMask(IntMaskType<'input>),
129 IntMaskOf(IntMaskOfType<'input>),
130 New(NewType<'input>),
131 TemplateType(TemplateTypeType<'input>),
132 IndexAccess(IndexAccessType<'input>),
133 Negated(NegatedType<'input>),
134 Posited(PositedType<'input>),
135 IntRange(IntRangeType<'input>),
136 PropertiesOf(PropertiesOfType<'input>),
137 Slice(SliceType<'input>),
138 Wildcard(WildcardType),
139}
140
141impl HasSpan for Type<'_> {
142 fn span(&self) -> Span {
143 match self {
144 Type::Parenthesized(ty) => ty.span(),
145 Type::Union(ty) => ty.span(),
146 Type::Intersection(ty) => ty.span(),
147 Type::Nullable(ty) => ty.span(),
148 Type::Array(ty) => ty.span(),
149 Type::NonEmptyArray(ty) => ty.span(),
150 Type::AssociativeArray(ty) => ty.span(),
151 Type::List(ty) => ty.span(),
152 Type::NonEmptyList(ty) => ty.span(),
153 Type::Iterable(ty) => ty.span(),
154 Type::ClassString(ty) => ty.span(),
155 Type::InterfaceString(ty) => ty.span(),
156 Type::EnumString(ty) => ty.span(),
157 Type::TraitString(ty) => ty.span(),
158 Type::Reference(ty) => ty.span(),
159 Type::Mixed(ty) => ty.span(),
160 Type::NonEmptyMixed(ty) => ty.span(),
161 Type::Null(ty) => ty.span(),
162 Type::Void(ty) => ty.span(),
163 Type::Never(ty) => ty.span(),
164 Type::Resource(ty) => ty.span(),
165 Type::ClosedResource(ty) => ty.span(),
166 Type::OpenResource(ty) => ty.span(),
167 Type::True(ty) => ty.span(),
168 Type::False(ty) => ty.span(),
169 Type::Bool(ty) => ty.span(),
170 Type::Float(ty) => ty.span(),
171 Type::Int(ty) => ty.span(),
172 Type::PositiveInt(ty) => ty.span(),
173 Type::NegativeInt(ty) => ty.span(),
174 Type::NonPositiveInt(ty) => ty.span(),
175 Type::NonNegativeInt(ty) => ty.span(),
176 Type::String(ty) => ty.span(),
177 Type::ArrayKey(ty) => ty.span(),
178 Type::Scalar(ty) => ty.span(),
179 Type::Object(ty) => ty.span(),
180 Type::Numeric(ty) => ty.span(),
181 Type::CallableString(ty) => ty.span(),
182 Type::LowercaseCallableString(ty) => ty.span(),
183 Type::UppercaseCallableString(ty) => ty.span(),
184 Type::NumericString(ty) => ty.span(),
185 Type::StringableObject(ty) => ty.span(),
186 Type::NonEmptyString(ty) => ty.span(),
187 Type::NonEmptyLowercaseString(ty) => ty.span(),
188 Type::LowercaseString(ty) => ty.span(),
189 Type::NonEmptyUppercaseString(ty) => ty.span(),
190 Type::UppercaseString(ty) => ty.span(),
191 Type::TruthyString(ty) => ty.span(),
192 Type::NonFalsyString(ty) => ty.span(),
193 Type::UnspecifiedLiteralInt(ty) => ty.span(),
194 Type::UnspecifiedLiteralString(ty) => ty.span(),
195 Type::UnspecifiedLiteralFloat(ty) => ty.span(),
196 Type::NonEmptyUnspecifiedLiteralString(ty) => ty.span(),
197 Type::LiteralFloat(ty) => ty.span(),
198 Type::LiteralInt(ty) => ty.span(),
199 Type::LiteralString(ty) => ty.span(),
200 Type::MemberReference(ty) => ty.span(),
201 Type::AliasReference(ty) => ty.span(),
202 Type::Shape(ty) => ty.span(),
203 Type::Callable(ty) => ty.span(),
204 Type::Conditional(ty) => ty.span(),
205 Type::Variable(ty) => ty.span(),
206 Type::KeyOf(ty) => ty.span(),
207 Type::ValueOf(ty) => ty.span(),
208 Type::IntMask(ty) => ty.span(),
209 Type::IntMaskOf(ty) => ty.span(),
210 Type::New(ty) => ty.span(),
211 Type::TemplateType(ty) => ty.span(),
212 Type::IndexAccess(ty) => ty.span(),
213 Type::Negated(ty) => ty.span(),
214 Type::Posited(ty) => ty.span(),
215 Type::IntRange(ty) => ty.span(),
216 Type::PropertiesOf(ty) => ty.span(),
217 Type::Slice(ty) => ty.span(),
218 Type::Wildcard(ty) => ty.span(),
219 }
220 }
221}
222
223impl std::fmt::Display for Type<'_> {
224 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
225 match self {
226 Type::Parenthesized(ty) => write!(f, "{ty}"),
227 Type::Union(ty) => write!(f, "{ty}"),
228 Type::Intersection(ty) => write!(f, "{ty}"),
229 Type::Nullable(ty) => write!(f, "{ty}"),
230 Type::Array(ty) => write!(f, "{ty}"),
231 Type::NonEmptyArray(ty) => write!(f, "{ty}"),
232 Type::AssociativeArray(ty) => write!(f, "{ty}"),
233 Type::List(ty) => write!(f, "{ty}"),
234 Type::NonEmptyList(ty) => write!(f, "{ty}"),
235 Type::Iterable(ty) => write!(f, "{ty}"),
236 Type::ClassString(ty) => write!(f, "{ty}"),
237 Type::InterfaceString(ty) => write!(f, "{ty}"),
238 Type::EnumString(ty) => write!(f, "{ty}"),
239 Type::TraitString(ty) => write!(f, "{ty}"),
240 Type::Reference(ty) => write!(f, "{ty}"),
241 Type::Mixed(ty) => write!(f, "{ty}"),
242 Type::NonEmptyMixed(ty) => write!(f, "{ty}"),
243 Type::Null(ty) => write!(f, "{ty}"),
244 Type::Void(ty) => write!(f, "{ty}"),
245 Type::Never(ty) => write!(f, "{ty}"),
246 Type::Resource(ty) => write!(f, "{ty}"),
247 Type::ClosedResource(ty) => write!(f, "{ty}"),
248 Type::OpenResource(ty) => write!(f, "{ty}"),
249 Type::True(ty) => write!(f, "{ty}"),
250 Type::False(ty) => write!(f, "{ty}"),
251 Type::Bool(ty) => write!(f, "{ty}"),
252 Type::Float(ty) => write!(f, "{ty}"),
253 Type::Int(ty) => write!(f, "{ty}"),
254 Type::PositiveInt(ty) => write!(f, "{ty}"),
255 Type::NegativeInt(ty) => write!(f, "{ty}"),
256 Type::NonPositiveInt(ty) => write!(f, "{ty}"),
257 Type::NonNegativeInt(ty) => write!(f, "{ty}"),
258 Type::String(ty) => write!(f, "{ty}"),
259 Type::ArrayKey(ty) => write!(f, "{ty}"),
260 Type::Scalar(ty) => write!(f, "{ty}"),
261 Type::Object(ty) => write!(f, "{ty}"),
262 Type::Numeric(ty) => write!(f, "{ty}"),
263 Type::CallableString(ty) => write!(f, "{ty}"),
264 Type::LowercaseCallableString(ty) => write!(f, "{ty}"),
265 Type::UppercaseCallableString(ty) => write!(f, "{ty}"),
266 Type::NumericString(ty) => write!(f, "{ty}"),
267 Type::StringableObject(ty) => write!(f, "{ty}"),
268 Type::NonEmptyString(ty) => write!(f, "{ty}"),
269 Type::NonEmptyLowercaseString(ty) => write!(f, "{ty}"),
270 Type::LowercaseString(ty) => write!(f, "{ty}"),
271 Type::NonEmptyUppercaseString(ty) => write!(f, "{ty}"),
272 Type::UppercaseString(ty) => write!(f, "{ty}"),
273 Type::TruthyString(ty) => write!(f, "{ty}"),
274 Type::NonFalsyString(ty) => write!(f, "{ty}"),
275 Type::UnspecifiedLiteralInt(ty) => write!(f, "{ty}"),
276 Type::UnspecifiedLiteralString(ty) => write!(f, "{ty}"),
277 Type::UnspecifiedLiteralFloat(ty) => write!(f, "{ty}"),
278 Type::NonEmptyUnspecifiedLiteralString(ty) => write!(f, "{ty}"),
279 Type::LiteralFloat(ty) => write!(f, "{ty}"),
280 Type::LiteralInt(ty) => write!(f, "{ty}"),
281 Type::LiteralString(ty) => write!(f, "{ty}"),
282 Type::MemberReference(ty) => write!(f, "{ty}"),
283 Type::AliasReference(ty) => write!(f, "{ty}"),
284 Type::Shape(ty) => write!(f, "{ty}"),
285 Type::Callable(ty) => write!(f, "{ty}"),
286 Type::Conditional(ty) => write!(f, "{ty}"),
287 Type::Variable(ty) => write!(f, "{ty}"),
288 Type::KeyOf(ty) => write!(f, "{ty}"),
289 Type::ValueOf(ty) => write!(f, "{ty}"),
290 Type::IntMask(ty) => write!(f, "{ty}"),
291 Type::IntMaskOf(ty) => write!(f, "{ty}"),
292 Type::New(ty) => write!(f, "{ty}"),
293 Type::TemplateType(ty) => write!(f, "{ty}"),
294 Type::IndexAccess(ty) => write!(f, "{ty}"),
295 Type::Negated(ty) => write!(f, "{ty}"),
296 Type::Posited(ty) => write!(f, "{ty}"),
297 Type::IntRange(ty) => write!(f, "{ty}"),
298 Type::PropertiesOf(ty) => write!(f, "{ty}"),
299 Type::Slice(ty) => write!(f, "{ty}"),
300 Type::Wildcard(ty) => write!(f, "{ty}"),
301 }
302 }
303}