oak_graphql/parser/
element_type.rs1use oak_core::{ElementType, Parser, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub enum GraphQLElementType {
9 StringLiteral,
11 IntLiteral,
13 FloatLiteral,
15 BooleanLiteral,
17 NullLiteral,
19 Name,
21 QueryKeyword,
23 MutationKeyword,
25 SubscriptionKeyword,
27 FragmentKeyword,
29 OnKeyword,
31 TypeKeyword,
33 InterfaceKeyword,
35 UnionKeyword,
37 ScalarKeyword,
39 EnumKeyword,
41 InputKeyword,
43 ExtendKeyword,
45 SchemaKeyword,
47 DirectiveKeyword,
49 ImplementsKeyword,
51 RepeatsKeyword,
53 Spread,
55 LeftParen,
57 RightParen,
59 LeftBracket,
61 RightBracket,
63 LeftBrace,
65 RightBrace,
67 Comma,
69 Colon,
71 Semicolon,
73 Pipe,
75 Ampersand,
77 Equals,
79 Exclamation,
81 At,
83 Dollar,
85 Whitespace,
87 Comment,
89 SourceFile,
91 Newline,
93 Eof,
95 Error,
97}
98
99impl GraphQLElementType {
100 pub fn is_keyword(&self) -> bool {
102 matches!(
103 self,
104 Self::QueryKeyword
105 | Self::MutationKeyword
106 | Self::SubscriptionKeyword
107 | Self::FragmentKeyword
108 | Self::OnKeyword
109 | Self::TypeKeyword
110 | Self::InterfaceKeyword
111 | Self::UnionKeyword
112 | Self::ScalarKeyword
113 | Self::EnumKeyword
114 | Self::InputKeyword
115 | Self::ExtendKeyword
116 | Self::SchemaKeyword
117 | Self::DirectiveKeyword
118 | Self::ImplementsKeyword
119 | Self::RepeatsKeyword
120 )
121 }
122}
123
124impl ElementType for GraphQLElementType {
125 type Role = UniversalElementRole;
126
127 fn role(&self) -> Self::Role {
128 match self {
129 Self::SourceFile => UniversalElementRole::Root,
130 Self::Error => UniversalElementRole::Error,
131 _ => UniversalElementRole::None,
132 }
133 }
134}
135
136impl From<crate::lexer::token_type::GraphQLTokenType> for GraphQLElementType {
137 fn from(token: crate::lexer::token_type::GraphQLTokenType) -> Self {
138 unsafe { std::mem::transmute(token) }
139 }
140}