mago_type_syntax/ast/
mod.rs

1use serde::Serialize;
2use strum::Display;
3
4use mago_span::HasSpan;
5use mago_span::Span;
6
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_range::*;
16pub use crate::ast::iterable::*;
17pub use crate::ast::key_of::*;
18pub use crate::ast::keyword::*;
19pub use crate::ast::literal::*;
20pub use crate::ast::properties_of::*;
21pub use crate::ast::reference::*;
22pub use crate::ast::shape::*;
23pub use crate::ast::unary::*;
24pub use crate::ast::value_of::*;
25pub use crate::ast::variable::*;
26
27pub mod array;
28pub mod callable;
29pub mod class_like_string;
30pub mod composite;
31pub mod conditional;
32pub mod generics;
33pub mod identifier;
34pub mod index_access;
35pub mod int_range;
36pub mod iterable;
37pub mod key_of;
38pub mod keyword;
39pub mod literal;
40pub mod properties_of;
41pub mod reference;
42pub mod shape;
43pub mod unary;
44pub mod value_of;
45pub mod variable;
46
47#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, PartialOrd, Ord, Display)]
48#[serde(tag = "type", content = "value")]
49pub enum Type<'input> {
50    Parenthesized(ParenthesizedType<'input>),
51    Union(UnionType<'input>),
52    Intersection(IntersectionType<'input>),
53    Nullable(NullableType<'input>),
54    Array(ArrayType<'input>),
55    NonEmptyArray(NonEmptyArrayType<'input>),
56    AssociativeArray(AssociativeArrayType<'input>),
57    List(ListType<'input>),
58    NonEmptyList(NonEmptyListType<'input>),
59    Iterable(IterableType<'input>),
60    ClassString(ClassStringType<'input>),
61    InterfaceString(InterfaceStringType<'input>),
62    EnumString(EnumStringType<'input>),
63    TraitString(TraitStringType<'input>),
64    Reference(ReferenceType<'input>),
65    Mixed(Keyword<'input>),
66    Null(Keyword<'input>),
67    Void(Keyword<'input>),
68    Never(Keyword<'input>),
69    Resource(Keyword<'input>),
70    ClosedResource(Keyword<'input>),
71    OpenResource(Keyword<'input>),
72    True(Keyword<'input>),
73    False(Keyword<'input>),
74    Bool(Keyword<'input>),
75    Float(Keyword<'input>),
76    Int(Keyword<'input>),
77    PositiveInt(Keyword<'input>),
78    NegativeInt(Keyword<'input>),
79    String(Keyword<'input>),
80    StringableObject(Keyword<'input>),
81    ArrayKey(Keyword<'input>),
82    Object(Keyword<'input>),
83    Numeric(Keyword<'input>),
84    Scalar(Keyword<'input>),
85    NumericString(Keyword<'input>),
86    NonEmptyString(Keyword<'input>),
87    LowercaseString(Keyword<'input>),
88    TruthyString(Keyword<'input>),
89    UnspecifiedLiteralInt(Keyword<'input>),
90    UnspecifiedLiteralString(Keyword<'input>),
91    NonEmptyUnspecifiedLiteralString(Keyword<'input>),
92    LiteralFloat(LiteralFloatType<'input>),
93    LiteralInt(LiteralIntType<'input>),
94    LiteralString(LiteralStringType<'input>),
95    MemberReference(MemberReferenceType<'input>),
96    Shape(ShapeType<'input>),
97    Callable(CallableType<'input>),
98    Variable(VariableType<'input>),
99    Conditional(ConditionalType<'input>),
100    KeyOf(KeyOfType<'input>),
101    ValueOf(ValueOfType<'input>),
102    IndexAccess(IndexAccessType<'input>),
103    Negated(NegatedType<'input>),
104    Posited(PositedType<'input>),
105    IntRange(IntRangeType<'input>),
106    PropertiesOf(PropertiesOfType<'input>),
107}
108
109impl HasSpan for Type<'_> {
110    fn span(&self) -> Span {
111        match self {
112            Type::Parenthesized(ty) => ty.span(),
113            Type::Union(ty) => ty.span(),
114            Type::Intersection(ty) => ty.span(),
115            Type::Nullable(ty) => ty.span(),
116            Type::Array(ty) => ty.span(),
117            Type::NonEmptyArray(ty) => ty.span(),
118            Type::AssociativeArray(ty) => ty.span(),
119            Type::List(ty) => ty.span(),
120            Type::NonEmptyList(ty) => ty.span(),
121            Type::Iterable(ty) => ty.span(),
122            Type::ClassString(ty) => ty.span(),
123            Type::InterfaceString(ty) => ty.span(),
124            Type::EnumString(ty) => ty.span(),
125            Type::TraitString(ty) => ty.span(),
126            Type::Reference(ty) => ty.span(),
127            Type::Mixed(ty) => ty.span(),
128            Type::Null(ty) => ty.span(),
129            Type::Void(ty) => ty.span(),
130            Type::Never(ty) => ty.span(),
131            Type::Resource(ty) => ty.span(),
132            Type::ClosedResource(ty) => ty.span(),
133            Type::OpenResource(ty) => ty.span(),
134            Type::True(ty) => ty.span(),
135            Type::False(ty) => ty.span(),
136            Type::Bool(ty) => ty.span(),
137            Type::Float(ty) => ty.span(),
138            Type::Int(ty) => ty.span(),
139            Type::PositiveInt(ty) => ty.span(),
140            Type::NegativeInt(ty) => ty.span(),
141            Type::String(ty) => ty.span(),
142            Type::ArrayKey(ty) => ty.span(),
143            Type::Scalar(ty) => ty.span(),
144            Type::Object(ty) => ty.span(),
145            Type::Numeric(ty) => ty.span(),
146            Type::NumericString(ty) => ty.span(),
147            Type::StringableObject(ty) => ty.span(),
148            Type::NonEmptyString(ty) => ty.span(),
149            Type::LowercaseString(ty) => ty.span(),
150            Type::TruthyString(ty) => ty.span(),
151            Type::UnspecifiedLiteralInt(ty) => ty.span(),
152            Type::UnspecifiedLiteralString(ty) => ty.span(),
153            Type::NonEmptyUnspecifiedLiteralString(ty) => ty.span(),
154            Type::LiteralFloat(ty) => ty.span(),
155            Type::LiteralInt(ty) => ty.span(),
156            Type::LiteralString(ty) => ty.span(),
157            Type::MemberReference(ty) => ty.span(),
158            Type::Shape(ty) => ty.span(),
159            Type::Callable(ty) => ty.span(),
160            Type::Conditional(ty) => ty.span(),
161            Type::Variable(ty) => ty.span(),
162            Type::KeyOf(ty) => ty.span(),
163            Type::ValueOf(ty) => ty.span(),
164            Type::IndexAccess(ty) => ty.span(),
165            Type::Negated(ty) => ty.span(),
166            Type::Posited(ty) => ty.span(),
167            Type::IntRange(ty) => ty.span(),
168            Type::PropertiesOf(ty) => ty.span(),
169        }
170    }
171}