mago_type_syntax/
token.rs

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