1use serde::Deserialize;
2use serde::Serialize;
3use strum::Display;
4
5use mago_span::Span;
6
7#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord, Display)]
8pub enum TypeTokenKind {
9 Int,
10 Integer,
11 String,
12 Float,
13 Real,
14 Double,
15 Bool,
16 Boolean,
17 False,
18 True,
19 Object,
20 Callable,
21 Array,
22 NonEmptyArray,
23 NonEmptyString,
24 NonEmptyLowercaseString,
25 NonFalsyString,
26 LowercaseString,
27 TruthyString,
28 Iterable,
29 Null,
30 Mixed,
31 NumericString,
32 ClassString,
33 InterfaceString,
34 TraitString,
35 EnumString,
36 StringableObject,
37 PureCallable,
38 PureClosure,
39 UnspecifiedLiteralString,
40 UnspecifiedLiteralInt,
41 UnspecifiedLiteralFloat,
42 NonEmptyUnspecifiedLiteralString,
43 Resource,
44 Void,
45 Scalar,
46 Numeric,
47 NoReturn,
48 NeverReturn,
49 NeverReturns,
50 Never,
51 Nothing,
52 ArrayKey,
53 List,
54 NonEmptyList,
55 OpenResource,
56 ClosedResource,
57 AssociativeArray,
58 KeyOf,
59 ValueOf,
60 IntMask,
61 IntMaskOf,
62 Min,
63 Max,
64 PropertiesOf,
65 PublicPropertiesOf,
66 PrivatePropertiesOf,
67 ProtectedPropertiesOf,
68 PositiveInt,
69 NegativeInt,
70 NonPositiveInt,
71 NonNegativeInt,
72 As,
73 Is,
74 Not,
75 Identifier,
76 QualifiedIdentifier,
77 FullyQualifiedIdentifier,
78 Plus,
79 Minus,
80 LessThan,
81 GreaterThan,
82 Pipe,
83 Ampersand,
84 Question,
85 Exclamation,
86 Comma,
87 Colon,
88 ColonColon,
89 LeftBrace,
90 RightBrace,
91 LeftBracket,
92 RightBracket,
93 LeftParenthesis,
94 RightParenthesis,
95 Equals,
96 Ellipsis,
97 PartialLiteralString,
98 LiteralString,
99 LiteralInteger,
100 LiteralFloat,
101 Variable,
102 Whitespace,
103 SingleLineComment,
104 Asterisk,
105}
106
107#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
108pub struct TypeToken<'input> {
109 pub kind: TypeTokenKind,
110 pub value: &'input str,
111 pub span: Span,
112}
113
114impl TypeTokenKind {
115 #[inline]
116 #[must_use]
117 pub const fn is_trivia(&self) -> bool {
118 matches!(self, Self::SingleLineComment | Self::Whitespace)
119 }
120
121 #[inline]
122 #[must_use]
123 pub const fn is_simple_identifier(&self) -> bool {
124 matches!(self, Self::Identifier)
125 }
126
127 #[inline]
128 #[must_use]
129 pub const fn is_identifier(&self) -> bool {
130 matches!(self, Self::Identifier | Self::QualifiedIdentifier | Self::FullyQualifiedIdentifier)
131 }
132
133 #[inline]
134 #[must_use]
135 pub const fn is_keyword(&self) -> bool {
136 matches!(
137 self,
138 Self::Int
139 | Self::Integer
140 | Self::Double
141 | Self::String
142 | Self::Float
143 | Self::Real
144 | Self::Bool
145 | Self::Boolean
146 | Self::False
147 | Self::True
148 | Self::Object
149 | Self::Callable
150 | Self::Array
151 | Self::NonEmptyArray
152 | Self::NonEmptyString
153 | Self::NonEmptyLowercaseString
154 | Self::LowercaseString
155 | Self::TruthyString
156 | Self::NonFalsyString
157 | Self::Iterable
158 | Self::Null
159 | Self::Mixed
160 | Self::NumericString
161 | Self::ClassString
162 | Self::InterfaceString
163 | Self::TraitString
164 | Self::EnumString
165 | Self::StringableObject
166 | Self::PureCallable
167 | Self::PureClosure
168 | Self::UnspecifiedLiteralString
169 | Self::UnspecifiedLiteralFloat
170 | Self::NonEmptyUnspecifiedLiteralString
171 | Self::Resource
172 | Self::Void
173 | Self::Scalar
174 | Self::Numeric
175 | Self::NoReturn
176 | Self::NeverReturn
177 | Self::NeverReturns
178 | Self::Never
179 | Self::Nothing
180 | Self::ArrayKey
181 | Self::List
182 | Self::NonEmptyList
183 | Self::OpenResource
184 | Self::ClosedResource
185 | Self::AssociativeArray
186 | Self::Is
187 | Self::As
188 | Self::Not
189 | Self::KeyOf
190 | Self::ValueOf
191 | Self::IntMask
192 | Self::IntMaskOf
193 | Self::Min
194 | Self::Max
195 | Self::UnspecifiedLiteralInt
196 | Self::PropertiesOf
197 | Self::PublicPropertiesOf
198 | Self::PrivatePropertiesOf
199 | Self::ProtectedPropertiesOf
200 | Self::PositiveInt
201 | Self::NegativeInt
202 | Self::NonPositiveInt
203 | Self::NonNegativeInt
204 )
205 }
206
207 #[inline]
208 #[must_use]
209 pub const fn is_array_like(&self) -> bool {
210 matches!(self, Self::Array | Self::NonEmptyArray | Self::AssociativeArray | Self::List | Self::NonEmptyList)
211 }
212}