oak_bash/kind/mod.rs
1use oak_core::SyntaxKind;
2use serde::Serialize;
3
4/// Represents all possible syntax kinds in the Bash shell scripting language.
5///
6/// This enum includes both terminal tokens (whitespace, literals, keywords, etc.)
7/// and non-terminal syntax nodes (source file, error nodes, etc.) that make up
8/// the abstract syntax tree of a Bash script.
9#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
10#[repr(u16)]
11pub enum BashSyntaxKind {
12 /// Whitespace characters (spaces, tabs)
13 Whitespace = 0,
14 /// Newline characters
15 Newline,
16 /// Comments (starting with #)
17 Comment,
18 /// String literals enclosed in quotes
19 StringLiteral,
20 /// Variable references (e.g., $VAR)
21 Variable,
22 /// Numeric literals
23 NumberLiteral,
24 /// Identifiers (variable names, function names, etc.)
25 Identifier,
26 /// Bash keywords (if, then, else, etc.)
27 Keyword,
28 /// Operators (&&, ||, >, <, etc.)
29 Operator,
30 /// Delimiters (;, (, ), {, }, etc.)
31 Delimiter,
32 /// Command names
33 Command,
34 /// File system paths
35 Path,
36 /// Here documents
37 Heredoc,
38 /// Glob patterns (*, ?, [])
39 GlobPattern,
40 /// Special characters with specific meaning
41 SpecialChar,
42 /// Plain text content
43 Text,
44 /// Root node representing the entire source file
45 SourceFile,
46 /// Error node for syntax errors
47 Error,
48 /// End of file marker
49 Eof,
50}
51
52impl SyntaxKind for BashSyntaxKind {
53 fn is_trivia(&self) -> bool {
54 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
55 }
56
57 fn is_comment(&self) -> bool {
58 matches!(self, Self::Comment)
59 }
60
61 fn is_whitespace(&self) -> bool {
62 matches!(self, Self::Whitespace | Self::Newline)
63 }
64
65 fn is_token_type(&self) -> bool {
66 true
67 }
68
69 fn is_element_type(&self) -> bool {
70 false
71 }
72}