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<'arena> {
64 Parenthesized(ParenthesizedType<'arena>),
65 Union(UnionType<'arena>),
66 Intersection(IntersectionType<'arena>),
67 Nullable(NullableType<'arena>),
68 Array(ArrayType<'arena>),
69 NonEmptyArray(NonEmptyArrayType<'arena>),
70 AssociativeArray(AssociativeArrayType<'arena>),
71 List(ListType<'arena>),
72 NonEmptyList(NonEmptyListType<'arena>),
73 Iterable(IterableType<'arena>),
74 ClassString(ClassStringType<'arena>),
75 InterfaceString(InterfaceStringType<'arena>),
76 EnumString(EnumStringType<'arena>),
77 TraitString(TraitStringType<'arena>),
78 Reference(ReferenceType<'arena>),
79 Mixed(Keyword<'arena>),
80 NonEmptyMixed(Keyword<'arena>),
81 Null(Keyword<'arena>),
82 Void(Keyword<'arena>),
83 Never(Keyword<'arena>),
84 Resource(Keyword<'arena>),
85 ClosedResource(Keyword<'arena>),
86 OpenResource(Keyword<'arena>),
87 True(Keyword<'arena>),
88 False(Keyword<'arena>),
89 Bool(Keyword<'arena>),
90 Float(Keyword<'arena>),
91 Int(Keyword<'arena>),
92 PositiveInt(Keyword<'arena>),
93 NegativeInt(Keyword<'arena>),
94 NonPositiveInt(Keyword<'arena>),
95 NonNegativeInt(Keyword<'arena>),
96 NonZeroInt(Keyword<'arena>),
97 String(Keyword<'arena>),
98 StringableObject(Keyword<'arena>),
99 ArrayKey(Keyword<'arena>),
100 Object(ObjectType<'arena>),
101 Numeric(Keyword<'arena>),
102 Scalar(Keyword<'arena>),
103 CallableString(Keyword<'arena>),
104 LowercaseCallableString(Keyword<'arena>),
105 UppercaseCallableString(Keyword<'arena>),
106 NumericString(Keyword<'arena>),
107 NonEmptyString(Keyword<'arena>),
108 NonEmptyLowercaseString(Keyword<'arena>),
109 LowercaseString(Keyword<'arena>),
110 NonEmptyUppercaseString(Keyword<'arena>),
111 UppercaseString(Keyword<'arena>),
112 TruthyString(Keyword<'arena>),
113 NonFalsyString(Keyword<'arena>),
114 UnspecifiedLiteralInt(Keyword<'arena>),
115 UnspecifiedLiteralString(Keyword<'arena>),
116 UnspecifiedLiteralFloat(Keyword<'arena>),
117 NonEmptyUnspecifiedLiteralString(Keyword<'arena>),
118 LiteralFloat(LiteralFloatType<'arena>),
119 LiteralInt(LiteralIntType<'arena>),
120 LiteralString(LiteralStringType<'arena>),
121 MemberReference(MemberReferenceType<'arena>),
122 AliasReference(AliasReferenceType<'arena>),
123 Shape(ShapeType<'arena>),
124 Callable(CallableType<'arena>),
125 Variable(VariableType<'arena>),
126 Conditional(ConditionalType<'arena>),
127 KeyOf(KeyOfType<'arena>),
128 ValueOf(ValueOfType<'arena>),
129 IntMask(IntMaskType<'arena>),
130 IntMaskOf(IntMaskOfType<'arena>),
131 New(NewType<'arena>),
132 TemplateType(TemplateTypeType<'arena>),
133 IndexAccess(IndexAccessType<'arena>),
134 Negated(NegatedType<'arena>),
135 Posited(PositedType<'arena>),
136 IntRange(IntRangeType<'arena>),
137 PropertiesOf(PropertiesOfType<'arena>),
138 Slice(SliceType<'arena>),
139 Wildcard(WildcardType),
140 TrailingPipe(TrailingPipeType<'arena>),
141 GlobalWildcardReference(GlobalWildcardType<'arena>),
142}
143
144impl HasSpan for Type<'_> {
145 fn span(&self) -> Span {
146 match self {
147 Type::Parenthesized(ty) => ty.span(),
148 Type::Union(ty) => ty.span(),
149 Type::Intersection(ty) => ty.span(),
150 Type::Nullable(ty) => ty.span(),
151 Type::Array(ty) => ty.span(),
152 Type::NonEmptyArray(ty) => ty.span(),
153 Type::AssociativeArray(ty) => ty.span(),
154 Type::List(ty) => ty.span(),
155 Type::NonEmptyList(ty) => ty.span(),
156 Type::Iterable(ty) => ty.span(),
157 Type::ClassString(ty) => ty.span(),
158 Type::InterfaceString(ty) => ty.span(),
159 Type::EnumString(ty) => ty.span(),
160 Type::TraitString(ty) => ty.span(),
161 Type::Reference(ty) => ty.span(),
162 Type::Mixed(ty) => ty.span(),
163 Type::NonEmptyMixed(ty) => ty.span(),
164 Type::Null(ty) => ty.span(),
165 Type::Void(ty) => ty.span(),
166 Type::Never(ty) => ty.span(),
167 Type::Resource(ty) => ty.span(),
168 Type::ClosedResource(ty) => ty.span(),
169 Type::OpenResource(ty) => ty.span(),
170 Type::True(ty) => ty.span(),
171 Type::False(ty) => ty.span(),
172 Type::Bool(ty) => ty.span(),
173 Type::Float(ty) => ty.span(),
174 Type::Int(ty) => ty.span(),
175 Type::PositiveInt(ty) => ty.span(),
176 Type::NegativeInt(ty) => ty.span(),
177 Type::NonPositiveInt(ty) => ty.span(),
178 Type::NonNegativeInt(ty) => ty.span(),
179 Type::NonZeroInt(ty) => ty.span(),
180 Type::String(ty) => ty.span(),
181 Type::ArrayKey(ty) => ty.span(),
182 Type::Scalar(ty) => ty.span(),
183 Type::Object(ty) => ty.span(),
184 Type::Numeric(ty) => ty.span(),
185 Type::CallableString(ty) => ty.span(),
186 Type::LowercaseCallableString(ty) => ty.span(),
187 Type::UppercaseCallableString(ty) => ty.span(),
188 Type::NumericString(ty) => ty.span(),
189 Type::StringableObject(ty) => ty.span(),
190 Type::NonEmptyString(ty) => ty.span(),
191 Type::NonEmptyLowercaseString(ty) => ty.span(),
192 Type::LowercaseString(ty) => ty.span(),
193 Type::NonEmptyUppercaseString(ty) => ty.span(),
194 Type::UppercaseString(ty) => ty.span(),
195 Type::TruthyString(ty) => ty.span(),
196 Type::NonFalsyString(ty) => ty.span(),
197 Type::UnspecifiedLiteralInt(ty) => ty.span(),
198 Type::UnspecifiedLiteralString(ty) => ty.span(),
199 Type::UnspecifiedLiteralFloat(ty) => ty.span(),
200 Type::NonEmptyUnspecifiedLiteralString(ty) => ty.span(),
201 Type::LiteralFloat(ty) => ty.span(),
202 Type::LiteralInt(ty) => ty.span(),
203 Type::LiteralString(ty) => ty.span(),
204 Type::MemberReference(ty) => ty.span(),
205 Type::AliasReference(ty) => ty.span(),
206 Type::Shape(ty) => ty.span(),
207 Type::Callable(ty) => ty.span(),
208 Type::Conditional(ty) => ty.span(),
209 Type::Variable(ty) => ty.span(),
210 Type::KeyOf(ty) => ty.span(),
211 Type::ValueOf(ty) => ty.span(),
212 Type::IntMask(ty) => ty.span(),
213 Type::IntMaskOf(ty) => ty.span(),
214 Type::New(ty) => ty.span(),
215 Type::TemplateType(ty) => ty.span(),
216 Type::IndexAccess(ty) => ty.span(),
217 Type::Negated(ty) => ty.span(),
218 Type::Posited(ty) => ty.span(),
219 Type::IntRange(ty) => ty.span(),
220 Type::PropertiesOf(ty) => ty.span(),
221 Type::Slice(ty) => ty.span(),
222 Type::Wildcard(ty) => ty.span(),
223 Type::TrailingPipe(ty) => ty.span(),
224 Type::GlobalWildcardReference(ty) => ty.span(),
225 }
226 }
227}
228
229impl std::fmt::Display for Type<'_> {
230 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
231 match self {
232 Type::Parenthesized(ty) => write!(f, "{ty}"),
233 Type::Union(ty) => write!(f, "{ty}"),
234 Type::Intersection(ty) => write!(f, "{ty}"),
235 Type::Nullable(ty) => write!(f, "{ty}"),
236 Type::Array(ty) => write!(f, "{ty}"),
237 Type::NonEmptyArray(ty) => write!(f, "{ty}"),
238 Type::AssociativeArray(ty) => write!(f, "{ty}"),
239 Type::List(ty) => write!(f, "{ty}"),
240 Type::NonEmptyList(ty) => write!(f, "{ty}"),
241 Type::Iterable(ty) => write!(f, "{ty}"),
242 Type::ClassString(ty) => write!(f, "{ty}"),
243 Type::InterfaceString(ty) => write!(f, "{ty}"),
244 Type::EnumString(ty) => write!(f, "{ty}"),
245 Type::TraitString(ty) => write!(f, "{ty}"),
246 Type::Reference(ty) => write!(f, "{ty}"),
247 Type::Mixed(ty) => write!(f, "{ty}"),
248 Type::NonEmptyMixed(ty) => write!(f, "{ty}"),
249 Type::Null(ty) => write!(f, "{ty}"),
250 Type::Void(ty) => write!(f, "{ty}"),
251 Type::Never(ty) => write!(f, "{ty}"),
252 Type::Resource(ty) => write!(f, "{ty}"),
253 Type::ClosedResource(ty) => write!(f, "{ty}"),
254 Type::OpenResource(ty) => write!(f, "{ty}"),
255 Type::True(ty) => write!(f, "{ty}"),
256 Type::False(ty) => write!(f, "{ty}"),
257 Type::Bool(ty) => write!(f, "{ty}"),
258 Type::Float(ty) => write!(f, "{ty}"),
259 Type::Int(ty) => write!(f, "{ty}"),
260 Type::PositiveInt(ty) => write!(f, "{ty}"),
261 Type::NegativeInt(ty) => write!(f, "{ty}"),
262 Type::NonPositiveInt(ty) => write!(f, "{ty}"),
263 Type::NonNegativeInt(ty) => write!(f, "{ty}"),
264 Type::NonZeroInt(ty) => write!(f, "{ty}"),
265 Type::String(ty) => write!(f, "{ty}"),
266 Type::ArrayKey(ty) => write!(f, "{ty}"),
267 Type::Scalar(ty) => write!(f, "{ty}"),
268 Type::Object(ty) => write!(f, "{ty}"),
269 Type::Numeric(ty) => write!(f, "{ty}"),
270 Type::CallableString(ty) => write!(f, "{ty}"),
271 Type::LowercaseCallableString(ty) => write!(f, "{ty}"),
272 Type::UppercaseCallableString(ty) => write!(f, "{ty}"),
273 Type::NumericString(ty) => write!(f, "{ty}"),
274 Type::StringableObject(ty) => write!(f, "{ty}"),
275 Type::NonEmptyString(ty) => write!(f, "{ty}"),
276 Type::NonEmptyLowercaseString(ty) => write!(f, "{ty}"),
277 Type::LowercaseString(ty) => write!(f, "{ty}"),
278 Type::NonEmptyUppercaseString(ty) => write!(f, "{ty}"),
279 Type::UppercaseString(ty) => write!(f, "{ty}"),
280 Type::TruthyString(ty) => write!(f, "{ty}"),
281 Type::NonFalsyString(ty) => write!(f, "{ty}"),
282 Type::UnspecifiedLiteralInt(ty) => write!(f, "{ty}"),
283 Type::UnspecifiedLiteralString(ty) => write!(f, "{ty}"),
284 Type::UnspecifiedLiteralFloat(ty) => write!(f, "{ty}"),
285 Type::NonEmptyUnspecifiedLiteralString(ty) => write!(f, "{ty}"),
286 Type::LiteralFloat(ty) => write!(f, "{ty}"),
287 Type::LiteralInt(ty) => write!(f, "{ty}"),
288 Type::LiteralString(ty) => write!(f, "{ty}"),
289 Type::MemberReference(ty) => write!(f, "{ty}"),
290 Type::AliasReference(ty) => write!(f, "{ty}"),
291 Type::Shape(ty) => write!(f, "{ty}"),
292 Type::Callable(ty) => write!(f, "{ty}"),
293 Type::Conditional(ty) => write!(f, "{ty}"),
294 Type::Variable(ty) => write!(f, "{ty}"),
295 Type::KeyOf(ty) => write!(f, "{ty}"),
296 Type::ValueOf(ty) => write!(f, "{ty}"),
297 Type::IntMask(ty) => write!(f, "{ty}"),
298 Type::IntMaskOf(ty) => write!(f, "{ty}"),
299 Type::New(ty) => write!(f, "{ty}"),
300 Type::TemplateType(ty) => write!(f, "{ty}"),
301 Type::IndexAccess(ty) => write!(f, "{ty}"),
302 Type::Negated(ty) => write!(f, "{ty}"),
303 Type::Posited(ty) => write!(f, "{ty}"),
304 Type::IntRange(ty) => write!(f, "{ty}"),
305 Type::PropertiesOf(ty) => write!(f, "{ty}"),
306 Type::Slice(ty) => write!(f, "{ty}"),
307 Type::Wildcard(ty) => write!(f, "{ty}"),
308 Type::TrailingPipe(ty) => write!(f, "{ty}"),
309 Type::GlobalWildcardReference(ty) => write!(f, "{ty}"),
310 }
311 }
312}