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