oak_clojure/kind/mod.rs
1use oak_core::SyntaxKind;
2
3/// Represents all possible syntax kinds in the Clojure programming language.
4///
5/// This enum defines the fundamental building blocks of Clojure syntax,
6/// including trivia, literals, identifiers, collections, special forms,
7/// reader macros, and composite nodes.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[repr(u16)]
10pub enum ClojureSyntaxKind {
11 // Trivia
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 /// Number literals (integer and floating-point)
25 NumberLiteral,
26 /// Boolean literals (true, false)
27 BooleanLiteral,
28 /// Nil literal
29 NilLiteral,
30 /// Keyword literals (e.g., :keyword)
31 KeywordLiteral,
32
33 // Identifiers and symbols
34 /// Symbol identifiers (e.g., variable names, function names)
35 Symbol,
36 /// Keyword identifiers (e.g., :keyword)
37 Keyword,
38
39 // Collections
40 /// List start delimiter: `(`
41 ListStart,
42 /// List end delimiter: `)`
43 ListEnd,
44 /// Vector start delimiter: `[`
45 VectorStart,
46 /// Vector end delimiter: `]`
47 VectorEnd,
48 /// Map start delimiter: `{`
49 MapStart,
50 /// Map end delimiter: `}`
51 MapEnd,
52 /// Set start delimiter: `#{`
53 SetStart,
54
55 // Special forms
56 /// Quote form (e.g., 'expr)
57 Quote,
58 /// Unquote form (e.g., ~expr)
59 Unquote,
60 /// Unquote-splicing form (e.g., ~@expr)
61 UnquoteSplice,
62 /// Deref form (e.g., @expr)
63 Deref,
64 /// Metadata form (e.g., ^metadata expr)
65 Meta,
66 /// Dispatch macro (e.g., #)
67 Dispatch,
68
69 // Reader macros
70 /// Reader macro form (e.g., #tag expr)
71 ReaderMacro,
72
73 // Regex
74 /// Regular expression literals (e.g., #"pattern")
75 RegexLiteral,
76
77 // Anonymous function
78 /// Anonymous function start delimiter: #(
79 AnonFnStart,
80 /// Anonymous function argument (e.g., %1, %2, etc.)
81 AnonFnArg,
82
83 // Composite nodes
84 /// Root node of the source file
85 SourceFile,
86
87 // Error handling
88 /// Error token
89 Error,
90 /// End of file marker
91 Eof,
92}
93
94impl SyntaxKind for ClojureSyntaxKind {
95 fn is_trivia(&self) -> bool {
96 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
97 }
98
99 fn is_comment(&self) -> bool {
100 matches!(self, Self::Comment)
101 }
102
103 fn is_whitespace(&self) -> bool {
104 matches!(self, Self::Whitespace | Self::Newline)
105 }
106
107 fn is_token_type(&self) -> bool {
108 matches!(
109 self,
110 Self::Whitespace
111 | Self::Newline
112 | Self::Comment
113 | Self::StringLiteral
114 | Self::CharacterLiteral
115 | Self::NumberLiteral
116 | Self::BooleanLiteral
117 | Self::NilLiteral
118 | Self::KeywordLiteral
119 | Self::Symbol
120 | Self::Keyword
121 | Self::ListStart
122 | Self::ListEnd
123 | Self::VectorStart
124 | Self::VectorEnd
125 | Self::MapStart
126 | Self::MapEnd
127 | Self::SetStart
128 | Self::Quote
129 | Self::Unquote
130 | Self::UnquoteSplice
131 | Self::Deref
132 | Self::Meta
133 | Self::Dispatch
134 | Self::ReaderMacro
135 | Self::RegexLiteral
136 | Self::AnonFnStart
137 | Self::AnonFnArg
138 | Self::Error
139 | Self::Eof
140 )
141 }
142
143 fn is_element_type(&self) -> bool {
144 matches!(self, Self::SourceFile)
145 }
146}