Skip to main content

mago_type_syntax/cst/
mod.rs

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