oak_graphql/kind/
mod.rs

1use oak_core::SyntaxKind;
2
3/// GraphQL 语法节点类型
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum GraphQLSyntaxKind {
6    // 字面量
7    StringLiteral,
8    IntLiteral,
9    FloatLiteral,
10    BooleanLiteral,
11    NullLiteral,
12
13    // 标识符和名称
14    Name,
15
16    // 关键字
17    QueryKeyword,
18    MutationKeyword,
19    SubscriptionKeyword,
20    FragmentKeyword,
21    OnKeyword,
22    TypeKeyword,
23    InterfaceKeyword,
24    UnionKeyword,
25    ScalarKeyword,
26    EnumKeyword,
27    InputKeyword,
28    ExtendKeyword,
29    SchemaKeyword,
30    DirectiveKeyword,
31    ImplementsKeyword,
32    RepeatsKeyword,
33
34    // 操作符
35    Spread, // ...
36
37    // 分隔符
38    LeftParen,    // (
39    RightParen,   // )
40    LeftBracket,  // [
41    RightBracket, // ]
42    LeftBrace,    // {
43    RightBrace,   // }
44    Comma,        // ,
45    Colon,        // :
46    Semicolon,    // ;
47    Pipe,         // |
48    Ampersand,    // &
49    Equals,       // =
50    Exclamation,  // !
51    At,           // @
52    Dollar,       // $
53
54    // 空白和注释
55    Whitespace,
56    Comment,
57
58    // 特殊
59    Newline,
60    Eof,
61    Error,
62}
63
64impl SyntaxKind for GraphQLSyntaxKind {
65    fn is_trivia(&self) -> bool {
66        matches!(self, Self::Whitespace | Self::Comment | Self::Newline)
67    }
68
69    fn is_comment(&self) -> bool {
70        matches!(self, Self::Comment)
71    }
72
73    fn is_whitespace(&self) -> bool {
74        matches!(self, Self::Whitespace | Self::Newline)
75    }
76
77    fn is_token_type(&self) -> bool {
78        !matches!(self, Self::Eof | Self::Error)
79    }
80
81    fn is_element_type(&self) -> bool {
82        matches!(self, Self::Eof | Self::Error)
83    }
84}