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