oak_cpp/kind/
mod.rs

1use oak_core::SyntaxKind;
2
3/// Represents all possible syntax kinds in the C++ programming language.
4///
5/// This enum defines the fundamental building blocks of C++ syntax,
6/// including trivia, literals, identifiers, keywords, operators,
7/// delimiters, preprocessor directives, and composite nodes.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[repr(u16)]
10pub enum CppSyntaxKind {
11    // Trivia tokens
12    /// Whitespace characters (spaces, tabs)
13    Whitespace,
14    /// Newline characters
15    Newline,
16    /// Comments (both single-line and multi-line)
17    Comment,
18
19    // Literals
20    /// String literals (e.g., "hello")
21    StringLiteral,
22    /// Character literals (e.g., 'a')
23    CharacterLiteral,
24    /// Integer literals (e.g., 42, 0xFF)
25    IntegerLiteral,
26    /// Floating-point literals (e.g., 3.14, 2.5e10)
27    FloatLiteral,
28    /// Boolean literals (true, false)
29    BooleanLiteral,
30
31    // Identifiers and keywords
32    /// Identifiers (variable names, function names, etc.)
33    Identifier,
34    /// Keywords (language reserved words)
35    Keyword,
36
37    // Operators
38    /// Plus operator: +
39    Plus,
40    /// Minus operator: -
41    Minus,
42    /// Multiplication operator: *
43    Star,
44    /// Division operator: /
45    Slash,
46    /// Modulo operator: %
47    Percent,
48    /// Assignment operator: =
49    Assign,
50    /// Plus-assignment operator: +=
51    PlusAssign,
52    /// Minus-assignment operator: -=
53    MinusAssign,
54    /// Multiply-assignment operator: *=
55    StarAssign,
56    /// Divide-assignment operator: /=
57    SlashAssign,
58    /// Modulo-assignment operator: %=
59    PercentAssign,
60    /// Equality operator: ==
61    Equal,
62    /// Inequality operator: !=
63    NotEqual,
64    /// Less-than operator: <
65    Less,
66    /// Greater-than operator: >
67    Greater,
68    /// Less-than-or-equal operator: <=
69    LessEqual,
70    /// Greater-than-or-equal operator: >=
71    GreaterEqual,
72    /// Logical AND operator: &&
73    LogicalAnd,
74    /// Logical OR operator: ||
75    LogicalOr,
76    /// Logical NOT operator: !
77    LogicalNot,
78    /// Bitwise AND operator: &
79    BitAnd,
80    /// Bitwise OR operator: |
81    BitOr,
82    /// Bitwise XOR operator: ^
83    BitXor,
84    /// Bitwise NOT operator: ~
85    BitNot,
86    /// Left shift operator: <<
87    LeftShift,
88    /// Right shift operator: >>
89    RightShift,
90    /// AND-assignment operator: &=
91    AndAssign,
92    /// OR-assignment operator: |=
93    OrAssign,
94    /// XOR-assignment operator: ^=
95    XorAssign,
96    /// Left shift-assignment operator: <<=
97    LeftShiftAssign,
98    /// Right shift-assignment operator: >>=
99    RightShiftAssign,
100    /// Increment operator: ++
101    Increment,
102    /// Decrement operator: --
103    Decrement,
104    /// Arrow operator: ->
105    Arrow,
106    /// Dot operator: .
107    Dot,
108    /// Ternary operator: ?
109    Question,
110    /// Colon operator: :
111    Colon,
112    /// Scope resolution operator: ::
113    Scope,
114
115    // Delimiters
116    /// Left parenthesis: (
117    LeftParen,
118    /// Right parenthesis: )
119    RightParen,
120    /// Left bracket: [
121    LeftBracket,
122    /// Right bracket: ]
123    RightBracket,
124    /// Left brace: {
125    LeftBrace,
126    /// Right brace: }
127    RightBrace,
128    /// Comma: ,
129    Comma,
130    /// Semicolon: ;
131    Semicolon,
132
133    // Preprocessor
134    /// Preprocessor directives (e.g., #include, #define)
135    Preprocessor,
136
137    // Composite nodes
138    /// Root node of the source file
139    SourceFile,
140    /// Error token
141    Error,
142    /// End of file marker
143    Eof,
144}
145
146impl SyntaxKind for CppSyntaxKind {
147    fn is_trivia(&self) -> bool {
148        matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
149    }
150
151    fn is_comment(&self) -> bool {
152        matches!(self, Self::Comment)
153    }
154
155    fn is_whitespace(&self) -> bool {
156        matches!(self, Self::Whitespace | Self::Newline)
157    }
158
159    fn is_token_type(&self) -> bool {
160        !matches!(self, Self::Error)
161    }
162
163    fn is_element_type(&self) -> bool {
164        matches!(self, Self::Error)
165    }
166}