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