oak_bash/parser/
element_type.rs1use crate::lexer::BashTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3use serde::Serialize;
4
5#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
7pub enum BashElementType {
8 Token(BashTokenType),
10 Root,
12 CommandStatement,
14 IfStatement,
16 ForStatement,
18 WhileStatement,
20 FunctionDefinition,
22 Error,
24}
25
26impl From<BashTokenType> for BashElementType {
27 fn from(token: BashTokenType) -> Self {
28 Self::Token(token)
29 }
30}
31
32impl ElementType for BashElementType {
33 type Role = UniversalElementRole;
34
35 fn is_root(&self) -> bool {
36 matches!(self, Self::Root)
37 }
38
39 fn is_error(&self) -> bool {
40 matches!(self, Self::Error)
41 }
42
43 fn role(&self) -> Self::Role {
44 match self {
45 Self::Root => UniversalElementRole::Root,
46 Self::FunctionDefinition => UniversalElementRole::Definition,
47 Self::CommandStatement | Self::IfStatement | Self::ForStatement | Self::WhileStatement => UniversalElementRole::Statement,
48 Self::Error => UniversalElementRole::Error,
49 _ => UniversalElementRole::None,
50 }
51 }
52}