oak_graphql/lexer/
token_type.rs1use oak_core::{Source, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2
3pub type GraphQLToken = Token<GraphQLTokenType>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum GraphQLTokenType {
10 StringLiteral,
12 IntLiteral,
14 FloatLiteral,
16 BooleanLiteral,
18 NullLiteral,
20 Name,
22 QueryKeyword,
24 MutationKeyword,
26 SubscriptionKeyword,
28 FragmentKeyword,
30 OnKeyword,
32 TypeKeyword,
34 InterfaceKeyword,
36 UnionKeyword,
38 ScalarKeyword,
40 EnumKeyword,
42 InputKeyword,
44 ExtendKeyword,
46 SchemaKeyword,
48 DirectiveKeyword,
50 ImplementsKeyword,
52 RepeatsKeyword,
54 Spread,
56 LeftParen,
58 RightParen,
60 LeftBracket,
62 RightBracket,
64 LeftBrace,
66 RightBrace,
68 Comma,
70 Colon,
72 Semicolon,
74 Pipe,
76 Ampersand,
78 Equals,
80 Exclamation,
82 At,
84 Dollar,
86 Whitespace,
88 Comment,
90 SourceFile,
92 Newline,
94 Eof,
96 Error,
98}
99
100impl GraphQLTokenType {
101 pub fn is_keyword(&self) -> bool {
103 matches!(
104 self,
105 Self::QueryKeyword
106 | Self::MutationKeyword
107 | Self::SubscriptionKeyword
108 | Self::FragmentKeyword
109 | Self::OnKeyword
110 | Self::TypeKeyword
111 | Self::InterfaceKeyword
112 | Self::UnionKeyword
113 | Self::ScalarKeyword
114 | Self::EnumKeyword
115 | Self::InputKeyword
116 | Self::ExtendKeyword
117 | Self::SchemaKeyword
118 | Self::DirectiveKeyword
119 | Self::ImplementsKeyword
120 | Self::RepeatsKeyword
121 )
122 }
123}
124
125impl TokenType for GraphQLTokenType {
126 type Role = UniversalTokenRole;
127 const END_OF_STREAM: Self = Self::Eof;
128
129 fn is_ignored(&self) -> bool {
130 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
131 }
132
133 fn role(&self) -> Self::Role {
134 match self {
135 Self::Whitespace => UniversalTokenRole::Whitespace,
136 Self::Newline => UniversalTokenRole::Whitespace,
137 Self::Comment => UniversalTokenRole::Comment,
138 Self::Eof => UniversalTokenRole::Eof,
139 Self::Error => UniversalTokenRole::Error,
140 _ => UniversalTokenRole::None,
141 }
142 }
143}