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 Null(Keyword<'input>),
75 Void(Keyword<'input>),
76 Never(Keyword<'input>),
77 Resource(Keyword<'input>),
78 ClosedResource(Keyword<'input>),
79 OpenResource(Keyword<'input>),
80 True(Keyword<'input>),
81 False(Keyword<'input>),
82 Bool(Keyword<'input>),
83 Float(Keyword<'input>),
84 Int(Keyword<'input>),
85 PositiveInt(Keyword<'input>),
86 NegativeInt(Keyword<'input>),
87 NonPositiveInt(Keyword<'input>),
88 NonNegativeInt(Keyword<'input>),
89 String(Keyword<'input>),
90 StringableObject(Keyword<'input>),
91 ArrayKey(Keyword<'input>),
92 Object(ObjectType<'input>),
93 Numeric(Keyword<'input>),
94 Scalar(Keyword<'input>),
95 NumericString(Keyword<'input>),
96 NonEmptyString(Keyword<'input>),
97 NonEmptyLowercaseString(Keyword<'input>),
98 LowercaseString(Keyword<'input>),
99 TruthyString(Keyword<'input>),
100 NonFalsyString(Keyword<'input>),
101 UnspecifiedLiteralInt(Keyword<'input>),
102 UnspecifiedLiteralString(Keyword<'input>),
103 UnspecifiedLiteralFloat(Keyword<'input>),
104 NonEmptyUnspecifiedLiteralString(Keyword<'input>),
105 LiteralFloat(LiteralFloatType<'input>),
106 LiteralInt(LiteralIntType<'input>),
107 LiteralString(LiteralStringType<'input>),
108 MemberReference(MemberReferenceType<'input>),
109 AliasReference(AliasReferenceType<'input>),
110 Shape(ShapeType<'input>),
111 Callable(CallableType<'input>),
112 Variable(VariableType<'input>),
113 Conditional(ConditionalType<'input>),
114 KeyOf(KeyOfType<'input>),
115 ValueOf(ValueOfType<'input>),
116 IntMask(IntMaskType<'input>),
117 IntMaskOf(IntMaskOfType<'input>),
118 IndexAccess(IndexAccessType<'input>),
119 Negated(NegatedType<'input>),
120 Posited(PositedType<'input>),
121 IntRange(IntRangeType<'input>),
122 PropertiesOf(PropertiesOfType<'input>),
123 Slice(SliceType<'input>),
124}
125
126impl HasSpan for Type<'_> {
127 fn span(&self) -> Span {
128 match self {
129 Type::Parenthesized(ty) => ty.span(),
130 Type::Union(ty) => ty.span(),
131 Type::Intersection(ty) => ty.span(),
132 Type::Nullable(ty) => ty.span(),
133 Type::Array(ty) => ty.span(),
134 Type::NonEmptyArray(ty) => ty.span(),
135 Type::AssociativeArray(ty) => ty.span(),
136 Type::List(ty) => ty.span(),
137 Type::NonEmptyList(ty) => ty.span(),
138 Type::Iterable(ty) => ty.span(),
139 Type::ClassString(ty) => ty.span(),
140 Type::InterfaceString(ty) => ty.span(),
141 Type::EnumString(ty) => ty.span(),
142 Type::TraitString(ty) => ty.span(),
143 Type::Reference(ty) => ty.span(),
144 Type::Mixed(ty) => ty.span(),
145 Type::Null(ty) => ty.span(),
146 Type::Void(ty) => ty.span(),
147 Type::Never(ty) => ty.span(),
148 Type::Resource(ty) => ty.span(),
149 Type::ClosedResource(ty) => ty.span(),
150 Type::OpenResource(ty) => ty.span(),
151 Type::True(ty) => ty.span(),
152 Type::False(ty) => ty.span(),
153 Type::Bool(ty) => ty.span(),
154 Type::Float(ty) => ty.span(),
155 Type::Int(ty) => ty.span(),
156 Type::PositiveInt(ty) => ty.span(),
157 Type::NegativeInt(ty) => ty.span(),
158 Type::NonPositiveInt(ty) => ty.span(),
159 Type::NonNegativeInt(ty) => ty.span(),
160 Type::String(ty) => ty.span(),
161 Type::ArrayKey(ty) => ty.span(),
162 Type::Scalar(ty) => ty.span(),
163 Type::Object(ty) => ty.span(),
164 Type::Numeric(ty) => ty.span(),
165 Type::NumericString(ty) => ty.span(),
166 Type::StringableObject(ty) => ty.span(),
167 Type::NonEmptyString(ty) => ty.span(),
168 Type::NonEmptyLowercaseString(ty) => ty.span(),
169 Type::LowercaseString(ty) => ty.span(),
170 Type::TruthyString(ty) => ty.span(),
171 Type::NonFalsyString(ty) => ty.span(),
172 Type::UnspecifiedLiteralInt(ty) => ty.span(),
173 Type::UnspecifiedLiteralString(ty) => ty.span(),
174 Type::UnspecifiedLiteralFloat(ty) => ty.span(),
175 Type::NonEmptyUnspecifiedLiteralString(ty) => ty.span(),
176 Type::LiteralFloat(ty) => ty.span(),
177 Type::LiteralInt(ty) => ty.span(),
178 Type::LiteralString(ty) => ty.span(),
179 Type::MemberReference(ty) => ty.span(),
180 Type::AliasReference(ty) => ty.span(),
181 Type::Shape(ty) => ty.span(),
182 Type::Callable(ty) => ty.span(),
183 Type::Conditional(ty) => ty.span(),
184 Type::Variable(ty) => ty.span(),
185 Type::KeyOf(ty) => ty.span(),
186 Type::ValueOf(ty) => ty.span(),
187 Type::IntMask(ty) => ty.span(),
188 Type::IntMaskOf(ty) => ty.span(),
189 Type::IndexAccess(ty) => ty.span(),
190 Type::Negated(ty) => ty.span(),
191 Type::Posited(ty) => ty.span(),
192 Type::IntRange(ty) => ty.span(),
193 Type::PropertiesOf(ty) => ty.span(),
194 Type::Slice(ty) => ty.span(),
195 }
196 }
197}
198
199impl std::fmt::Display for Type<'_> {
200 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
201 match self {
202 Type::Parenthesized(ty) => write!(f, "{ty}"),
203 Type::Union(ty) => write!(f, "{ty}"),
204 Type::Intersection(ty) => write!(f, "{ty}"),
205 Type::Nullable(ty) => write!(f, "{ty}"),
206 Type::Array(ty) => write!(f, "{ty}"),
207 Type::NonEmptyArray(ty) => write!(f, "{ty}"),
208 Type::AssociativeArray(ty) => write!(f, "{ty}"),
209 Type::List(ty) => write!(f, "{ty}"),
210 Type::NonEmptyList(ty) => write!(f, "{ty}"),
211 Type::Iterable(ty) => write!(f, "{ty}"),
212 Type::ClassString(ty) => write!(f, "{ty}"),
213 Type::InterfaceString(ty) => write!(f, "{ty}"),
214 Type::EnumString(ty) => write!(f, "{ty}"),
215 Type::TraitString(ty) => write!(f, "{ty}"),
216 Type::Reference(ty) => write!(f, "{ty}"),
217 Type::Mixed(ty) => write!(f, "{ty}"),
218 Type::Null(ty) => write!(f, "{ty}"),
219 Type::Void(ty) => write!(f, "{ty}"),
220 Type::Never(ty) => write!(f, "{ty}"),
221 Type::Resource(ty) => write!(f, "{ty}"),
222 Type::ClosedResource(ty) => write!(f, "{ty}"),
223 Type::OpenResource(ty) => write!(f, "{ty}"),
224 Type::True(ty) => write!(f, "{ty}"),
225 Type::False(ty) => write!(f, "{ty}"),
226 Type::Bool(ty) => write!(f, "{ty}"),
227 Type::Float(ty) => write!(f, "{ty}"),
228 Type::Int(ty) => write!(f, "{ty}"),
229 Type::PositiveInt(ty) => write!(f, "{ty}"),
230 Type::NegativeInt(ty) => write!(f, "{ty}"),
231 Type::NonPositiveInt(ty) => write!(f, "{ty}"),
232 Type::NonNegativeInt(ty) => write!(f, "{ty}"),
233 Type::String(ty) => write!(f, "{ty}"),
234 Type::ArrayKey(ty) => write!(f, "{ty}"),
235 Type::Scalar(ty) => write!(f, "{ty}"),
236 Type::Object(ty) => write!(f, "{ty}"),
237 Type::Numeric(ty) => write!(f, "{ty}"),
238 Type::NumericString(ty) => write!(f, "{ty}"),
239 Type::StringableObject(ty) => write!(f, "{ty}"),
240 Type::NonEmptyString(ty) => write!(f, "{ty}"),
241 Type::NonEmptyLowercaseString(ty) => write!(f, "{ty}"),
242 Type::LowercaseString(ty) => write!(f, "{ty}"),
243 Type::TruthyString(ty) => write!(f, "{ty}"),
244 Type::NonFalsyString(ty) => write!(f, "{ty}"),
245 Type::UnspecifiedLiteralInt(ty) => write!(f, "{ty}"),
246 Type::UnspecifiedLiteralString(ty) => write!(f, "{ty}"),
247 Type::UnspecifiedLiteralFloat(ty) => write!(f, "{ty}"),
248 Type::NonEmptyUnspecifiedLiteralString(ty) => write!(f, "{ty}"),
249 Type::LiteralFloat(ty) => write!(f, "{ty}"),
250 Type::LiteralInt(ty) => write!(f, "{ty}"),
251 Type::LiteralString(ty) => write!(f, "{ty}"),
252 Type::MemberReference(ty) => write!(f, "{ty}"),
253 Type::AliasReference(ty) => write!(f, "{ty}"),
254 Type::Shape(ty) => write!(f, "{ty}"),
255 Type::Callable(ty) => write!(f, "{ty}"),
256 Type::Conditional(ty) => write!(f, "{ty}"),
257 Type::Variable(ty) => write!(f, "{ty}"),
258 Type::KeyOf(ty) => write!(f, "{ty}"),
259 Type::ValueOf(ty) => write!(f, "{ty}"),
260 Type::IntMask(ty) => write!(f, "{ty}"),
261 Type::IntMaskOf(ty) => write!(f, "{ty}"),
262 Type::IndexAccess(ty) => write!(f, "{ty}"),
263 Type::Negated(ty) => write!(f, "{ty}"),
264 Type::Posited(ty) => write!(f, "{ty}"),
265 Type::IntRange(ty) => write!(f, "{ty}"),
266 Type::PropertiesOf(ty) => write!(f, "{ty}"),
267 Type::Slice(ty) => write!(f, "{ty}"),
268 }
269 }
270}